php > require_once('System.php');
php > System::users();
PHP Fatal error: Call to undefined method System::users() in php shell code on line 1
This seems to happen both from interactive command-line and from the a simple script:
<?php
require_once('System.php');
var_dump(System::users());
?>
System.php is in the PHP include path - and includes properly:
php > echo (class_exists('System')) ? 'THERE!' : 'WHERE?';
WHERE?
php > require_once('System.php');
php > echo (class_exists('System')) ? 'THERE!' : 'WHERE?';
THERE!
php > System::users();
PHP Fatal error: Call to undefined method System::users() in php shell code on line 1
I'm having a hard time grasping why it says there is a call to an undefined method when in fact it's static, it's there, and should be accessible.
<?php
class System
{
public static function users()
{
$users = array();
if( !$data_array = file('/etc/passwd') )
{
return false;
}
foreach( $data_array as $line )
{
$data = explode(":", $line);
$user = array_shift($data);
list(, $uid, $gid, $info, $path, $terminal) = $data;
$tmp = array();
$tmp['uid'] = $uid;
$tmp['gid'] = $gid;
$tmp['name'] = array_shift(explode(',', $info));
$tmp['path'] = $path;
$tmp['terminal'] = $terminal;
$users[$user] = $tmp;
unset($tmp);
}
return $users;
}
public static function user( $user )
{
$users = self::users();
if( array_key_exists($user, $users) )
{
return $users[$user];
}
else
{
return false;
}
}
}
?>
PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:49:46)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies