note 53838 deleted from language.oop5.decon by felipe
| From: | felipe@php.net | Date: | Sat, 15 Dec 2007 01:30:12 +0000 |
| Subject: | note 53838 deleted from language.oop5.decon by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133497@lists.php.net to get a copy of this message | ||
Note Submitter: luancarvalho at terra dot com dot br
----
Even PHP 5 doesn't allow to redeclare a method in a class. So, it's impossible to create
differents constructors to a object with unique parameters, something common JAVA.
To overcome this limitation I've been forced to use something like this:
<?php
class MyClass {
public $n1;
public $n2;
function MyClass ($n1 = FALSE, $n2 = FALSE) {
if ($n1) {
$this->n1 = $n1;
} else {
$this->n1 = 0;
}
if ($n2) {
$this->n2 = $n2;
} else {
$this->n2 = mt_rand();
}
}
}
?>