note 106136 added to language.oop5.overloading

From: Date: Thu, 13 Oct 2011 12:31:09 +0000
Subject: note 106136 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-183848@lists.php.net to get a copy of this message
If you need to try and imitate the functionality of the __get() and __set() magic methods whilst outside of the object-scope (i.e. using a static method) this small __callStatic() implementation may help you out. <?php class config { private static $_propertyArray = array(); public static function __callStatic( $method, $args ) { $property = $args[0]; switch( $method ) { case 'set': // set property self::$_propertyArray[ $property ] = $args[1]; break; case 'get': // get property if( isset( self::$_propertyArray[ $property ] ) ) { return self::$_propertyArray[ $property ]; } else { throw new Exception( "Property ({$property}) does not exist", 0 ); } break; default: // do nothing.. break; } } } config::set( 'my_property', 'someValue' ); print "The value of 'my_property' is: " . config::get( 'my_property' ); // Will output: The value of 'my_property' is: someValue ?> ---- Server IP: 69.147.83.197 Probable Submitter: 77.99.25.91 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/106136 Del: integrated -- https://master.php.net/note/delete/106136/integrated Del: useless -- https://master.php.net/note/delete/106136/useless Del: bad code -- https://master.php.net/note/delete/106136/bad+code Del: spam -- https://master.php.net/note/delete/106136/spam Del: non-english -- https://master.php.net/note/delete/106136/non-english Del: in docs -- https://master.php.net/note/delete/106136/in+docs Del: other reasons-- https://master.php.net/note/delete/106136 Reject -- https://master.php.net/note/reject/106136 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183848) next »