[ create a new paste ] login | about

Link: http://codepad.org/eSt4Xcpr    [ raw code | output | fork ]

PHP, pasted on Dec 6:
<?php

class Person 
{
    private $name;

    public function __construct($name)
    {
        $this->name = $name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }
}

function changeName(Person $person)
{
    $person->setName("Michael");
}

function changePerson(Person &$person)
    {
        $person = new Person("Jerry");
    }

    $person = new Person("John");

    changeName($person);
    echo $person->getName() . PHP_EOL;
    
    changePerson($person);
    echo $person->getName() . PHP_EOL;


Output:
1
2
Michael
Jerry


Create a new paste based on this one


Comments: