Re: Calling parent function with call_user_func_array

From: Date: Fri, 30 Nov 2007 00:56:59 +0000
Subject: Re: Calling parent function with call_user_func_array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-265269@lists.php.net to get a copy of this message
On Nov 29, 2007 7:22 PM, Tommy Baggett <me@tommyb.com> wrote: > Here's the exact code I tried: > > class Walker_NavBar extends Walker { > ... > > function walk($elements, $to_depth) { > $args = func_get_args(); > > ... > > // call base class implementation > return call_user_func_array(array(parent,'walk'),$args); > } > ... wow; i was just looking at the wordpress source; not the prettiest code ive ever seen.. anyway; in what context do you intend to use the subclass? why dont you just create a proxy instead? eg. (php4) class WalkerProxy { var $walkerInstance = null; /** * constructor * accept an existing walker instance or create one from scratch */ function WalkerProxy($existingWalker=null) { if(!is_null($existingWalker) && is_a($existingWalker, 'Walker') { $this->walkerInstance = $existingWalker; } else { $this->walkerInstance = new Walker(); } } /** * walk * do custom WalkerProxy stuff then invoke the underlying Walker's walk() method */ function walk($elements, $to_depth) { //// do something custom here return $this->walkerInstance($elements, $to_depth); } /// ..... } -nathan

« previous php.general (#265269) next »