php.net |  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
Votes:2
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ziya at atilim dot edu dot tr
New email:
PHP Version: OS:

 

 [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;
<?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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-03 06:02 UTC] phanto@php.net
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;
	}
}

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC