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
Tester isn't in the global namespace. It's in the my namespace.
Both of these will work:
$classname = '\my\Tester';
$classname = 'my\Tester';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With