note 69567 deleted from ref.overload by bjori
| From: | bjori@php.net | Date: | Mon, 11 Sep 2006 09:53:20 +0000 |
| Subject: | note 69567 deleted from ref.overload by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117007@lists.php.net to get a copy of this message | ||
Note Submitter: Timo 'SiSaSyco'
Reason: bad code
----
You mix Objectproperty with Arrays. You cant access Arrayelements like Objectproperties.
If you want your Code to run correct try this (But i dont think its intended to be used like this):
<?php
class SillyClass
{
private $config = array();
public function __construct()
{
$this->config['fruit'] = 'banana';
$this->config['animal'] = 'monkey';
$this->config['shoppingList'] =
array('drink' => 'milk', 'food' =>
'cheeseburger');
}
//Allow mySillyClass->someProperty style getting of
//anything that might happen to be in the $config array
//(returns NULL if not in the $config array).
public function __get($property)
{
if(isset($this->config[$property]))
{
return $this->config[$property];
}
return NULL;
}
}
$mySillyClass = new SillyClass();
echo $drinkToBuy = $mySillyClass->shoppingList['drink'];
?>