note 90896 added to language.oop5.overloading

From: Date: Fri, 15 May 2009 04:16:27 +0000
Subject: note 90896 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-154624@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. /** * 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; } ---- Server IP: 64.71.164.2 Probable Submitter: 206.169.197.253 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/90896 Del: integrated -- https://master.php.net/note/delete/90896/integrated Del: useless -- https://master.php.net/note/delete/90896/useless Del: bad code -- https://master.php.net/note/delete/90896/bad+code Del: spam -- https://master.php.net/note/delete/90896/spam Del: non-english -- https://master.php.net/note/delete/90896/non-english Del: in docs -- https://master.php.net/note/delete/90896/in+docs Del: other reasons-- https://master.php.net/note/delete/90896 Reject -- https://master.php.net/note/reject/90896 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154624) next »