Re: include() and duplicate function definition
| From: | Thijs Lensselink | Date: | Wed, 03 Nov 2010 10:18:11 +0000 |
| Subject: | Re: include() and duplicate function definition | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309263@lists.php.net to get a copy of this message | ||
On Wed, 3 Nov 2010 17:59:06 +0800, David Nelson <commerce@traduction.biz> wrote:
Hi, :-) I'm making a child theme for WordPress. I need to rewrite one function defined in "../sometheme/functions/actions.php" and put that rewritten function in "wp-content/themes/sometheme-child/functions/actions.php". But I want to preserve "../sometheme/functions/actions.php" unchanged in any way. (Future theme updates would just overwrite any changes I made.) So, in my new "actions.php", I put an include followed by the replacement function definition, named identically to the one I want to replace: <?php include '../sometheme/functions/actions.php'; function foo($arg_1, $arg_2, /* ..., */ $arg_n) {As far as I know it is not possible to overwrite functions in PHP (unless you use runkit, apd). Inside classes this is possible. But that's not the case here. Why do the functions have to be equally named? Try to create a new function and call the original function from there if needed... foo2() { foo() }echo "All my new code.\n";} ?> Because this duplicate foo() function definition comes after the foo() defined in the included file, does it replace the included foo()? Or how can I achieve what I want? Big thanks in advance for any suggestions. :-) David