note 114427 added to reserved.classes

From: Date: Wed, 19 Feb 2014 18:43:53 +0000
Subject: note 114427 added to reserved.classes
Groups: php.notes 
Request: Send a blank email to php-notes+get-198552@lists.php.net to get a copy of this message
Here a simple class that allow to set anonymous function. It's an optimised class of stdClass. <?php class stdObject { public function __construct(array $arguments = array()) { if (!empty($arguments)) { foreach ($arguments as $property => $argument) { if ($argument instanceOf Closure) { $this->{$property} = $argument; } else { $this->{$property} = $argument; } } } } public function __call($method, $arguments) { if (isset($this->{$method}) && is_callable($this->{$method})) { return call_user_func_array($this->{$method}, $arguments); } else { throw new Exception("Fatal error: Call to undefined method stdObject::{$method}()"); } } } $person = new stdObject(array( "name" => "nick", "age" => 23, "friends" => array("frank", "sally", "aaron"), "sayHi" => function() { return "Hello there"; } )); $person->sayHi2 = function() { return "Hello there 2"; }; $person->test = function() { return "test"; }; var_dump($person->name, $person->test(), $person->sayHi2()); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/reserved.classes.php Edit -- https://master.php.net/note/edit/114427 Del: integrated -- https://master.php.net/note/delete/114427/integrated Del: useless -- https://master.php.net/note/delete/114427/useless Del: bad code -- https://master.php.net/note/delete/114427/bad+code Del: spam -- https://master.php.net/note/delete/114427/spam Del: non-english -- https://master.php.net/note/delete/114427/non-english Del: in docs -- https://master.php.net/note/delete/114427/in+docs Del: other reasons-- https://master.php.net/note/delete/114427 Reject -- https://master.php.net/note/reject/114427 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198552) next »