php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52684 document problem with class_exists function
Submitted: 2010-08-24 08:03 UTC Modified: 2010-08-24 15:10 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: chinawolfs at hotmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.14 OS: window xp
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chinawolfs at hotmail dot com
New email:
PHP Version: OS:

 

 [2010-08-24 08:03 UTC] chinawolfs at hotmail dot com
Description:
------------
<?php
class php {
	private $_url = null;
	public function home($url) {
		$this->_url = $url;
		return $this->_url;
	}
}
if(class_exists('php')) {
	$php = new php();
}
print_r($php->home());
?>

when class_exists('php') eq true .the code have to process $php = new php();
but I see php manual "Returns TRUE if class_name is a defined class, FALSE 
otherwise"
if the class_name is a defined or true,and I don't new a object.

Test script:
---------------
<?php
class php {
	private $_url = null;
	public function home($url) {
		$this->_url = $url;
		return $this->_url;
	}
}
if(class_exists('php')) {
	$php = new php();
}
print_r($php->home());
?>

Expected result:
----------------
$php is a new object and print_r home() method


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-24 09:49 UTC] salathe@php.net
-Status: Open +Status: Feedback
 [2010-08-24 09:49 UTC] salathe@php.net
Your sample code will raise a warning on line 4 (Missing argument 1 for 
php::home()) and a notice on line 5 (Undefined variable: url); it will create a 
new instance of the php class.  If a value is passed along to the method call, 
your script works fine. 

Could you elaborate on the nature of the documentation bug, please? I don't see 
it.
 [2010-08-24 09:58 UTC] chinawolfs at hotmail dot com
-Status: Feedback +Status: Open
 [2010-08-24 09:58 UTC] chinawolfs at hotmail dot com
sorry ,I forget the url argument.
but I don't express oneself clearly idear with english.
The class_exists method Return Value is 
"Returns TRUE if class_name is a defined class, FALSE otherwise.".
if(class_exists('php')) {
	$php = new php();
}
if class_exists('php') is true ,and then $php = new php() could process.
but 'php' is not defined class.
 [2010-08-24 15:10 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-08-24 15:10 UTC] cataphract@php.net
> if class_exists('php') is true ,and then $php = new php() could process.
but 'php' is not defined class.

Yes, it is. You just defined it above: "class php {". I'm closing this as bogus.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 13:00:02 2026 UTC