#22512 [Opn->Bgs]: returning NULL from constructor does no MEAN
| From: | phanto@php.net | Date: | Mon, 03 Mar 2003 12:02:26 +0000 |
| Subject: | #22512 [Opn->Bgs]: returning NULL from constructor does no MEAN | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-34662@lists.php.net to get a copy of this message | ||
ID: 22512
Updated by: phanto@php.net
Reported By: ziya at atilim dot edu dot tr
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Any
PHP Version: 4.3.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
next time post your questsions on php-general@lists.php.net first
before filing a bogus bug report. use:
class Test{
var $myVar;
function Test($val){
if (is_null($val))
$this = NULL;
else
$this->myVar = $val;
}
}
Previous Comments:
------------------------------------------------------------------------
[2003-03-03 02:39:27] ziya at atilim dot edu dot tr
When we return NULL from the constructor, our intend is to tell caller
that NO OBJECT IS CREATED. But in PHP this case does not work.
Please check the following example;
<?php
class Test{
var $myVar;
function Test($val){
if (is_null($val))
return NULL;
else
$this->myVar = $val;
return $this;
}
}
$a = NULL;
$t = new Test($a);
if (is_object($t))
echo "Although it must be NULL, it says OBJECT";
?>
I am developing a very huge API using PHP and this does not permit us
to continue. I think, there should be a way of doing this in a language
which support OOP constructs.
Sincerely,
Ziya Karakaya
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=22512&edit=1