<?php
/**
* http://www.php.net/manual/en/language.variables.scope.php
*/
class ClassWithPropertiesThatHaveTheSameName
{
private $name = 'something';
// here they are the same, but differentiated
public function setName($name)
{
$this->name = $name;
}
/**
* @returns String|Other
*/
public function getName()
{
return $this->name;
}
/**
* @returns Array|Transversable
*/
public function getAndTestLocalVariableNameArray()
{
$name = array('value' => $this->name);
return $name;
}
}
$same = new ClassWithPropertiesThatHaveTheSameName();
$same->setName('oranges and pecans in a tea from a tree');
echo $same->getName() . "\n\n";
print_r($same->getAndTestLocalVariableNameArray());
?>
oranges and pecans in a tea from a tree
Array
(
[value] => oranges and pecans in a tea from a tree
)
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/MZ24v on line 8
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/MZ24v on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/MZ24v on line 8
Process exited with code 255.