Can't figure it out how it works...
Posted: Mon Nov 12, 2007 5:03 am
Hi there,
I am reading a book on PHP. There is the example codes in the book:
In the other script:
In the above codes, the class Address has no properties declared. I am not sure where the $this->state and $this->address come from?
And the double underscore (__set and __get) does have some real functionalities in the programming or it is just a way the PHP programmers will do? If I use "_set" or "set" instead of "__set" will change the program?
Thanks.
Dave
I am reading a book on PHP. There is the example codes in the book:
Code: Select all
<?php
abstract class PropertyObject implements Validator {
protected $propertyTable = array();
protected $data;
....
function __construct($arData) {
$this->data = $arData;
}
function __get($propertyName) {
...
}
function __set($propertyName, $value) {
...
if (method_exists($this, 'set'. $propertyName)) {
return call_user_func(array($this, 'set' . $propertyName), $value);
} else ...
...
}
}
?>Code: Select all
<?php
...
class Address extends PropertyObject {
function __construct($arData) {
parent::__construct($arData);
$this->propertyTable['address']='addressid';
$this->propertyTable['state']='cstate';
...
}
function validate() {
if(strlen($this->state) !=2 ) { ... } // Where does $this->state come from?
...
if (!$this->address) { ... } // Again, where does $this->address come from?
...
}
}
?>And the double underscore (__set and __get) does have some real functionalities in the programming or it is just a way the PHP programmers will do? If I use "_set" or "set" instead of "__set" will change the program?
Thanks.
Dave