note 97918 modified in language.oop5.overloading by danbrown
| From: | danbrown@php.net | Date: | Sat, 15 May 2010 20:27:29 +0000 |
| Subject: | note 97918 modified in language.oop5.overloading by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169293@lists.php.net to get a copy of this message | ||
If you want to make it work more naturally for arrays $obj->variable[] etc you'll need to
return __get by reference.
<?php
class Variables
{
public function __construct()
{
if(session_id() === "")
{
session_start();
}
}
public function __set($name,$value)
{
$_SESSION["Variables"][$name] = $value;
}
public function &__get($name)
{
return $_SESSION["Variables"][$name];
}
public function __isset($name)
{
return isset($_SESSION["Variables"][$name]);
}
}
?>
--was--
If you want to make it work more naturally for arrays $obj->variable[] etc you'll need to
return __get by reference.
<?php
class Variables
{
public function __construct()
{
if(session_id() === "")
{
session_start();
}
}
public function __set($name,$value)
{
$_SESSION["Variables"][$name] = $value;
}
public function &__get($name)
{
return $_SESSION["Variables"][$name];
}
public function __isset($name)
{
return isset($_SESSION["Variables"][$name]);
}
}
http://php.net/manual/en/language.oop5.overloading.php