|
Server IP : 127.0.0.1 / Your IP : 127.0.0.1 Web Server : Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3 System : Windows NT WIN-R7LTCC7BPLI 6.3 build 9200 (Windows Server 2012 R2 Datacenter Edition) i586 User : GerbangSIPAD ( 0) PHP Version : 5.6.3 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF Directory (0777) : C:/xampp8.1/php/tests/Structures_Graph/../parseFile/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
/**
* This Person class encapsulates a couple of properties which
* a person might have: their name and age.
* We also give the Person the opportunity to introduce themselves.
*
* @link http://cowburn.info/php/php5-method-chaining/
*/
class Person
{
var $m_szName;
var $m_iAge;
function setName($szName)
{
$this->m_szName = $szName;
return $this; // We now return $this (the Person)
}
function setAge($iAge)
{
$this->m_iAge = $iAge;
return $this; // Again, return our Person
}
function introduce()
{
printf('Hello my name is %s and I am %d years old.',
$this->m_szName,
$this->m_iAge);
}
}
// We'll be creating me, digitally.
$peter = new Person();
// Let's set some attributes and let me introduce myself,
// all in one line of code.
$peter->setName('Peter')->setAge(23)->introduce();
?>