note 103374 added to language.oop5.decon

From: Date: Mon, 11 Apr 2011 09:38:48 +0000
Subject: note 103374 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-178676@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.197 Probable Submitter: 156.116.8.86 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- https://master.php.net/note/edit/103374 Del: integrated -- https://master.php.net/note/delete/103374/integrated Del: useless -- https://master.php.net/note/delete/103374/useless Del: bad code -- https://master.php.net/note/delete/103374/bad+code Del: spam -- https://master.php.net/note/delete/103374/spam Del: non-english -- https://master.php.net/note/delete/103374/non-english Del: in docs -- https://master.php.net/note/delete/103374/in+docs Del: other reasons-- https://master.php.net/note/delete/103374 Reject -- https://master.php.net/note/reject/103374 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178676) next »