Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Overriding parent methods with __call
    primarykey
    data
    text
    <p>I'd like to hide parent methods in some manner so that a child class's __call magic method is invoked for methods defined on the parent. For example:</p> <pre><code>class C { function foo() { echo "foo\n"; } } class D extends C { function __call( $method, $args ) { echo "called $name\n"; } } $d = new D(); $d-&gt;foo(); // desired result: called foo // actual result: foo </code></pre> <p>I've checked into rename_function and override_function but those don't work for methods. ReflectionMethod has a setAccessible method I tried, but that seems to only work if you use the ReflectionMethod instance to invoke the method.</p> <p>Background: attempting to have an RPC Proxy class that can take advantage of PHP's type checking. So, if I have an RPCFoo I can use type hinting or instanceof to enforce type in such a way that I can check that ($RPCFoo instance Foo).</p> <p>Edit: the base class should be able to be used as is, without the proxy. This is so that proxying can be part of the system configuration, not the code. Think multiple servers all with the same code base, but the ability to assign certain tasks to each. If the local server does not handle the service requested, the class loader would return a proxy instead of the base class. If the local server does handle the service requested, it would return the base class.</p> <p>Edit Again: the methods presented are workable, but hide the designed interface of the base class from IDEs and reflection. I was attempting to make the proxy implementation clean so that one simply had to inherit from the base class and implement a proxy interface. In order to maintain the base class interface, the proxy developer would have to re-implement all the public and protected methods to make a remote call. Then when something is updated in the base class, the proxy would have to be updated as well. In the end, I think I'm simply going to go the route of writing a proxy generator that uses reflection do this for the developer.</p> <p>Thanks for the replies!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload