Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- error_reporting(E_ALL|E_STRICT);
- class Joe {
- public $lastName;
- }
- $joe = new Joe();
- $joe->lastNombre = "Smith";
- echo "And here it is " . $jose;
- <?php
- error_reporting( E_ALL | E_STRICT );
- class Joe {
- public $lastName;
- public function __set( $name, $value ) {
- if ( !property_exists( $this, $name ) ) {
- trigger_error( 'Undefined property via __set(): ' . $name, E_USER_NOTICE );
- return null;
- }
- $this->$name = $value;
- }
- public function __get( $name ) {
- if ( !property_exists( $this, $name ) ) {
- trigger_error( 'Undefined property via __get(): ' . $name, E_USER_NOTICE );
- return null;
- }
- return $this->$name;
- }
- }
- $joe = new Joe();
- $joe->lastNom = "Smith";
- echo $joe->lastNom , "n";
- ?>
- // Reporting E_NOTICE can be good too (to report uninitialized
- // variables or catch variable name misspellings ...)
- error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
- error_reporting(E_ALL|E_STRICT);
- error_reporting(E_ALL);
- php_error_reporting=5
- <?php
- /**
- * Abstract
- * Some default Abstract functions that everything should extend
- *
- * @package example
- * @subpackage lib
- */
- /**
- * Class mh_abstract
- * Some default MH Abstract functions that everything should extend
- *
- * @package example
- * @subpackage lib
- */
- abstract class lib_abstract
- {
- /**
- * Throws an error if php magic set is called
- *
- * @param string $key
- * @param string|object $value
- *
- * @throws Exception When trying to set a new class property
- */
- final public function __set($key, $value)
- {
- // get if the thing we are trying to set is a object
- if(is_object($value))
- {
- // if so let's just report it's name, not the full object
- $value = 'object:'.get_class($value);
- }
- // throw the error!
- throw new mh_lib_error_dev_unknownClassProperty('Tried to set new property '.$key.' with value '.$value);
- }
- /**
- * Throws an error if php magic get is called
- *
- * @param string $key
- *
- * @throws Exception When trying to set a new class property
- */
- final public function __get($key)
- {
- // throw the error!
- throw new mh_lib_error_dev_unknownClassProperty('Tried to get new property '.$key);
- }
- }
- function __set($sKey, $sValue)
- {
- // any setter data should be *returned* here
- // NOTE: this function will only get called if the property is not
- // publicly accessible.
- trigger_error("Non-existing property name ".$sKey, E_USER_WARNING);
- }
Add Comment
Please, Sign In to add comment