note 99903 added to language.oop5.decon

From: Date: Tue, 14 Sep 2010 10:35:21 +0000
Subject: note 99903 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-172537@lists.php.net to get a copy of this message
the easiest way to use and understand multiple constructors: <?php class A { function __construct() { $a = func_get_args(); $i = func_num_args(); if (method_exists($this,$f='__construct'.$i)) { call_user_func_array(array($this,$f),$a); } } function __construct1($a1) { echo('__construct with 1 param called: '.$a1.PHP_EOL); } function __construct2($a1,$a2) { echo('__construct with 2 params called: '.$a1.','.$a2.PHP_EOL); } function __construct3($a1,$a2,$a3) { echo('__construct with 3 params called: '.$a1.','.$a2.','.$a3.PHP_EOL); } } $o = new A('sheep'); $o = new A('sheep','cat'); $o = new A('sheep','cat','dog'); // results: // __construct with 1 param called: sheep // __construct with 2 params called: sheep,cat // __construct with 3 params called: sheep,cat,dog ---- Server IP: 212.124.37.9 Probable Submitter: 85.8.70.161 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- https://master.php.net/note/edit/99903 Del: integrated -- https://master.php.net/note/delete/99903/integrated Del: useless -- https://master.php.net/note/delete/99903/useless Del: bad code -- https://master.php.net/note/delete/99903/bad+code Del: spam -- https://master.php.net/note/delete/99903/spam Del: non-english -- https://master.php.net/note/delete/99903/non-english Del: in docs -- https://master.php.net/note/delete/99903/in+docs Del: other reasons-- https://master.php.net/note/delete/99903 Reject -- https://master.php.net/note/reject/99903 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172537) next »