Are you planning on moving into more OOP? If so, worry about using a collection later on.
Whilst you can do what you want to do, the better alternative is to deal with it as a collection of object data instead of a collection of scalar data.
public function __construct($userid, $firstName, $lastName)
$this->userid = $userid;
$this->firstName = $firstName;
$this->lastName = $lastName;
public function getUserID()
public function getFirstName()
public function getLastName()
class UserList extends ArrayObject
public function displayAsTable() // or you could even override the __toString if you want.
$sOutput = '<table><tbody>';
foreach ($this AS $user)
$sOutput .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $user->getUserID(), $user->getFirstName(), $user->getLastName());
$sOutput .= print '</tbody></table>';
// ah, what the hell.
public function __toString()
$ul = new UserList();
$ul = new User(1, 'S.', 'Fraise');
$ul = new User(2, 'Fou', 'Lu');
This you cannot do:
. That is a static access whilst the method is non-static. It doesn't refer to $this, so it would actually run, but it doesn't carry a lot of use since the data it bases on is constant. You could instead write the method to be static and accept an argument:
public static function displayAsTable(ArrayObject $ao);
One downside with this is PHP's datatype weakness. This particular collection wants user but there is no guarantee it will get it. To deal with that, you need to override the append and offsetSet methods to check for its datatype before allowing it to be added to the list. Trivial to implement.