Skip to content

Instantly share code, notes, and snippets.

@flevour
Created May 4, 2011 18:50
Show Gist options
  • Save flevour/955768 to your computer and use it in GitHub Desktop.
Save flevour/955768 to your computer and use it in GitHub Desktop.
__toString example implementation
<?php
class Person
{
protected $name = NULL, $surname = NULL;
public function __construct($name, $surname)
{
$this->name = $name;
$this->surname = $surname;
}
public function getName()
{
return $this->name;
}
public function getSurname()
{
return $this->surname;
}
public function __toString()
{
return sprintf("%s, %s", $this->surname, $this->name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment