note 90896 modified in language.oop5.overloading by thiago

From: Date: Fri, 15 May 2009 04:22:41 +0000
Subject: note 90896 modified in language.oop5.overloading by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154625@lists.php.net to get a copy of this message
Here's a handy little routine to suggest properties you're trying to set that don't exist. For example: Attempted to __get() non-existant property/variable 'operator_id' in class 'User'. checking for operator and suggesting the following: * id_operator * operator_name * operator_code enjoy. <?php /** * Suggests alternative properties should a __get() or __set() fail * * @param string $property * @return string * @author Daevid Vincent [daevid@daevid.com] * @date 05/12/09 * @see __get(), __set(), __call() */ public function suggest_alternative($property) { $parts = explode('_',$property); foreach($parts as $i => $p) if ($p == '_' || $p == 'id') unset($parts[$i]); echo 'checking for <b>'.implode(', ',$parts)."</b> and suggesting the following:<br/>\n"; echo "<ul>"; foreach($this as $key => $value) foreach($parts as $p) if (stripos($key, $p) !== false) print '<li>'.$key."</li>\n"; echo "</ul>"; } just put it in your __get() or __set() like so: public function __get($property) { echo "<p><font color='#ff0000'>Attempted to __get() non-existant property/variable '".$property."' in class '".$this->get_class_name()."'.</font><p>\n"; $this->suggest_alternative($property); exit; } ?> --was-- Here's a handy little routine to suggest properties you're trying to set that don't exist. For example: Attempted to __get() non-existant property/variable 'operator_id' in class 'User'. checking for operator and suggesting the following: * id_operator * operator_name * operator_code enjoy. /** * Suggests alternative properties should a __get() or __set() fail * * @param string $property * @return string * @author Daevid Vincent [daevid@daevid.com] * @date 05/12/09 * @see __get(), __set(), __call() */ public function suggest_alternative($property) { $parts = explode('_',$property); foreach($parts as $i => $p) if ($p == '_' || $p == 'id') unset($parts[$i]); echo 'checking for <b>'.implode(', ',$parts)."</b> and suggesting the following:<br/>\n"; echo "<ul>"; foreach($this as $key => $value) foreach($parts as $p) if (stripos($key, $p) !== false) print '<li>'.$key."</li>\n"; echo "</ul>"; } just put it in your __get() or __set() like so: public function __get($property) { echo "<p><font color='#ff0000'>Attempted to __get() non-existant property/variable '".$property."' in class '".$this->get_class_name()."'.</font><p>\n"; $this->suggest_alternative($property); exit; } http://php.net/manual/en/language.oop5.overloading.php

« previous php.notes (#154625) next »