note 55524 added to language.oop5.decon

From: Date: Fri, 05 Aug 2005 19:43:03 +0000
Subject: note 55524 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-93143@lists.php.net to get a copy of this message
IMHO using func_get_args() is superior to constructor polymorphism, because you don't have to define constructors for every possible way a class can be initialized. The pattern I use looks like this; all you have to do is pass the parameters in the correct order. <?php class Movie { public $title; public $director; public $stars; public $year_released; public function __construct() { $args = func_get_args(); foreach(array("title", "director", "stars", "year_released") as $i) { if(empty($args)) { break; } $this->$i = array_shift($args); } } } ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55524 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55524&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55524&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55524&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55524&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55524&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55524&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55524&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93143) next »