Bug #69220 [NEW]: _call, __construct, __set

From: Date: Wed, 11 Mar 2015 11:12:58 +0000
Subject: Bug #69220 [NEW]: _call, __construct, __set
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191308@lists.php.net to get a copy of this message
From: cybermerlin at ya dot ru Operating system: winx64_8.1 PHP version: 5.6.6 Package: Class/Object related Bug Type: Bug Bug description:_call, __construct, __set Description: ------------ 1) in __construct I wrote creator of methods hasSomeField for each field. But if I tried to invoke it, then nothing happens. 2) in __call I added writer to LOG name executing method, but in LOG exists only Exception for 'hasSomeField'. Test script: --------------- class Base{ protected $funcs = []; public function __call($name, $args) { error_log("\t>>>Call [$name](". json_encode($args). ") \r\n",3, LOGFILE); if (method_exists($this, $name)) { return call_user_func_array($this->$name, $args); } else if (isset($this->funcs[ $name ])) { return call_user_func_array($this->funcs[ $name ], $args); } else { throw new Exception("Method <$name> is not accessible."); } } /** * @param array $args * * @example new Base(["field1"=>"value1", "field2"=>"value2"]) * if u need override __constructor, then use: * __construct($args){ * .. * parent::__construct($args); * } */ public function __construct($args = []) { $nameClass = get_class($this); #region auto create methods 'hasField' for everyone field\property (if there exists getter or setter) $properties = get_class_vars($nameClass); $keys = array_keys($properties); foreach ($keys AS $k) { if ((method_exists($this, "set" . ucfirst($k)) || method_exists($this, "get" . ucfirst($k))) && (!method_exists($this, "has" . ucfirst($k) && !isset($this->funcs["has" . ucfirst($k)]))) ) { $v = &$this->$k; $this->funcs["has" . ucfirst($k)] = function () use (&$v) { return !empty($v); }; } } #endregion foreach ($args as $k => $v) { if (property_exists($nameClass, $k)) { $this->$k = $v; } } } -- Edit bug report at https://bugs.php.net/bug.php?id=69220&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69220&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69220&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69220&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69220&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69220&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69220&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69220&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69220&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69220&r=support Expected behavior: https://bugs.php.net/fix.php?id=69220&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69220&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69220&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69220&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69220&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69220&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69220&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69220&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69220&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69220&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69220&r=mysqlcfg

« previous php.bugs (#191308) next »