note 22759 added to function.printf
| From: | sam@php.net | Date: | Fri, 28 Jun 2002 16:45:33 +0000 |
| Subject: | note 22759 added to function.printf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32374@lists.php.net to get a copy of this message | ||
I don't know if this is useful to anyone, but here goes! Example for using the printf function
to output an object.
class person
{
var $name = "";
function name($newname = NULL)
{
if(! is_null($newname))
{
$this->name=$newname;
}
return $this->name;
}
var $surname = "";
function surname($newsurname = NULL)
{
if(! is_null($newsurname))
{
$this->surname=$newsurname;
}
return $this->surname;
}
var $age = "";
function age($newage = NULL)
{
if(! is_null($newage))
{
$this->age=$newage;
}
return $this->age;
}
}
$bob = new person;
$bob->name('Bob');
$bob->surname('Builder');
$bob->age('50');
printf("Hi %s, your surname is %s and you are %s years old", $bob->name,
$bob->surname, $bob->age);
Outputs:
Hi Bob, your surname is Builder and you are 50 years old
--
http://www.php.net/manual/en/function.printf.php
http://master.php.net/manage/user-notes.php?action=edit+22759
http://master.php.net/manage/user-notes.php?action=delete+22759
http://master.php.net/manage/user-notes.php?action=reject+22759