|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22512 returning NULL from constructor does no MEAN
Submitted: 2003-03-03 02:39 UTC Modified: 2003-03-03 06:02 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: ziya at atilim dot edu dot tr Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.1 OS: Any
Private report: No CVE-ID: None
 [2003-03-03 02:39 UTC] 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;

class Test{
	var $myVar;
	function Test($val){
		if (is_null($val))
			return NULL;
			$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.

Ziya Karakaya


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-03 06:02 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

next time post your questsions on first before filing a bogus bug report. use:

class Test{
	var $myVar;
	function Test($val){
		if (is_null($val))
			$this = NULL;
			$this->myVar = $val;

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Feb 24 01:01:27 2024 UTC