I don’t have PHP 5.2 installed to test on.
I want to use if (class_exists('Composer\Autoload\ClassLoader')) to test whether composer is installed, however my code needs to be compatible with PHP 5.2.
Will PHP 5.2 get stuck on the backslash characters? Or will it just return false and continue on with the script?
Namespaces don’t exist in PHP 5.2 — they were added as a new feature in PHP 5.3.
So the direct answer to your question is yes, PHP 5.2 will get stuck on the backslashes, because as far as it’s concerned, it’s not valid syntax.
The line of code you quoted is not in itself syntactically invalid, since as you point out, it’s just a string. Passing it into
class_exists()may or may not break things though — I also don’t have a copy of PHP 5.2 handy any more to confirm. If I were to guess, I would expect it to throw some kind of warning or notice rather than blowing up completely.But composer itself won’t work with 5.2, so if the user is on 5.2 then by definition they can’t have Composer installed. I would suggest therefore that you could avoid the whole issue by checking the PHP version directly first, by calling
phpversion()andversion_compare(). This will allow you to avoid any unpleasantness with theclass_exists()call.