note 103374 deleted from language.oop5.decon by danbrown

From: Date: Mon, 11 Apr 2011 15:36:50 +0000
Subject: note 103374 deleted from language.oop5.decon by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178701@lists.php.net to get a copy of this message
Note Submitter: halbach at nr dot no ---- Great idea; however, there are 2 issues with the last example. 1) $constructor must be assigned before it is used in method_exists 2) It gives a loop for a constructor without arguments. Improved code below: $args = func_get_args(); if( count( $args) ) { $argsStr = ''; foreach ( $args as $arg) { $argsStr .= '_'.gettype( $arg); } $constructor = '__construct'.$argsStr; if ( method_exists( $this, $constructor) ) call_user_func_array( array( $this, $constructor), $args); else throw new Exception('Error: No Constructor ('.get_class().$constructor.')', NULL, NULL); } // if( count( $args

« previous php.notes (#178701) next »