__call(), __get() and __set() in PHP4
Posted: Mon Aug 13, 2007 8:35 pm
You have been keeping this secret from me you rapscallions!
I don't know how I could have missed the overload() function in PHP! It seems that since PHP 4.3.0 you have been able to have __call(), __get() and __set() in PHP4. Well, it is a little late now to be to useful ... but it could have been -- even though the syntax is slightly different.
Try the following code in PHP4:
I don't know how I could have missed the overload() function in PHP! It seems that since PHP 4.3.0 you have been able to have __call(), __get() and __set() in PHP4. Well, it is a little late now to be to useful ... but it could have been -- even though the syntax is slightly different.
Try the following code in PHP4:
Code: Select all
<?php
error_reporting(E_NONE);
class Test {
var $_data = array();
function __call($method, $args, &$return) {
echo "__call: $method(" . implode (',', $args) . ')<br/>';
}
function __get($prop_name, &$prop_value) {
$prop_value = isset($this->_data[$prop_name]) ? $this->_data[$prop_name] : null;
echo "__get: $prop_name, $prop_value<br/>";
}
function __set($prop_name, $prop_value) {
$this->_data[$prop_name] = $prop_value;
echo "__set: $prop_name, $prop_value<br/>";
}
}
overload ('Test');
$test =& new Test();
$test->foo();
$test->bar = 'foo';
$test = $test->bar;
echo "test->bar = $test<br/>";