note 49108 deleted from ref.overload by sobak

From: Date: Tue, 22 Nov 2016 03:50:01 +0000
Subject: note 49108 deleted from ref.overload by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207451@lists.php.net to get a copy of this message
Note Submitter: evert at rooftopsolutions dot nl ---- I use the overloader to perform a method-level permission check for objects <? class MyClass { function method1() { // .... // } function method2() { // .... // } } class ObjectProtector { var $obj; function ObjectProtector(&$object) { $this->obj =& $object; } function __call($m,$a,&$r) { if (myPermissionChecker(...)) { $r = call_user_func_array(array($this->obj,$m),$a); return true; } else return false; } } overload('ObjectProtector'); // Create your object $myObj = new MyClass; // Prodect your object $myProtectedObj = new ObjectProtector($myObj); //call your methods trough $myProtectedObj $myProtectedObj->method1(); $myProtectedObj->method2('arguments'); ?> I'm not sure this is bad practice, but the engine allows it and it seems right.

« previous php.notes (#207451) next »