Created
May 4, 2011 18:50
-
-
Save flevour/955768 to your computer and use it in GitHub Desktop.
__toString example implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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