note 91258 modified in language.oop5.paamayim-nekudotayim by danbrown

From: Date: Tue, 02 Jun 2009 13:50:34 +0000
Subject: note 91258 modified in language.oop5.paamayim-nekudotayim by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156290@lists.php.net to get a copy of this message
Well, a "swiss knife" couple of code lines to call parent method. The only limit is you can't use it with "by reference" parameters. Main advantage you dont need to know the "actual" signature of your super class, you just need to know which arguments do you need <?php class someclass extends some superclass { // usable for constructors function __construct($ineedthisone) { $args=func_get_args(); /* $args will contain any argument passed to __construct. * Your formal argument doesnt influence the way func_get_args() works */ call_user_func_array(array('parent',__FUNCTION__),$args); } // but this is not for __construct only function anyMethod() { $args=func_get_args(); call_user_func_array(array('parent',__FUNCTION__),$args); } // Note: php 5.3.0 will even let you do function anyMethod() { //Needs php >=5.3.x call_user_func_array(array('parent',__FUNCTION__),func_get_args()); } } ?> --was-- Well, a "swiss knife" couple of code lines to call parent method. The only limit is you can't use it with "by reference" parameters. Main advantage you dont need to know the "actual" signature of your super class, you just need to know which arguments do you need <? class someclass extends some superclass { // usable for constructors function __construct($ineedthisone) { $args=func_get_args(); /* $args will contain any argument passed to __construct. * Your formal argument doesnt influence the way func_get_args() works */ call_user_func_array(array('parent',__FUNCTION__),$args); } // but this is not for __construct only function anyMethod() { $args=func_get_args(); call_user_func_array(array('parent',__FUNCTION__),$args); } // Note: php 5.3.0 will even let you do function anyMethod() { //Needs php >=5.3.x call_user_func_array(array('parent',__FUNCTION__),func_get_args()); } } http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php

« previous php.notes (#156290) next »