Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Car
- {
- public $manufacturer;
- public $model;
- public $color;
- private $_extraData = array();
- /**
- * __get() gets called when code try to read invisible property
- * @param unknown $propertyName
- * @return multitype:|NULL
- */
- public function __get( $propertyName )
- {
- if( array_key_exists( $propertyName , $this->_extraData) )
- {
- return $this->_extraData[$propertyName];
- }
- else
- {
- return null;
- }
- }
- /**
- * __set() gets called when code try to write invsible property of the object
- * @param unknown $propertyName
- * @param unknown $propertyValue
- */
- public function __set( $propertyName , $propertyValue )
- {
- $this->_extraData[$propertyName] = $propertyValue;
- echo "<pre>";
- print_r($this->_extraData);
- echo "</pre>";
- }
- }
- $myCar = new Car();
- $myCar->manufacturer = "Volkswagen";
- $myCar->model = "Beetle";
- $myCar->color = "red";
- $myCar->engineSize = 1.8;
- $myCar->otherColors = array( "green" , "blue" , "purple" );
- // var_dump( $myCar->otherColors );
- var_dump( property_exists( "Car" , 'engineSize' ) );
- var_dump( property_exists( "Car" , 'color' ) );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement