In the following script I check the class_exists function. What is the scope of this function ? It returns false for this script when I test for this class.
<?php
namespace my;
class Tester {
public function check() {
$classname = 'Tester';
if(class_exists($classname)) {
echo "class exists ! <br />";
} else {
echo "class doesn't exist ! <br />";
}
}
}
$obj = new Tester();
$obj->check();
Output : class doesn’t exist
Testerisn’t in the global namespace. It’s in themynamespace.Both of these will work: