Instanceof operator returns false for true condition

I am very confused why the php statement instanceofinsists that LVALUE is not an instance of a particular class here when it get_classsays that it is.

class WhereIn {
    public function __construct($args) {
        echo "is instanceof: " . ($args[0] instanceof ActiveRecordField) . EOL;
        echo "get class: " . get_class($args[0]) . EOL;
    }
}

Exit from this method:

is instanceof: 
get class: ActiveRecordField

For reference, I am using PHP 5.6.9.

+4
source share
1 answer

If you use namespaces in your code, you need to provide it directly:

if ($args[0] instanceof ActiveRecordField) // False

if ($args[0] instanceof \MyCompany\Classes\ActiveRecordField) // True
+2
source

All Articles