php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43987 parse error when second instanceof operand is function call
Submitted: 2008-01-31 01:42 UTC Modified: 2008-02-02 13:22 UTC
From: ms419 at freezone dot co dot uk Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.5 OS: Debian
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: ms419 at freezone dot co dot uk
New email:
PHP Version: OS:

 

 [2008-01-31 01:42 UTC] ms419 at freezone dot co dot uk
Description:
------------
PHP raises a parse error when the second operand of an instanceof operator is a function call. In my case, the function call, $relatedTable->getPhpName(), returns the class name as a string, which I want to determine whether $obj is an instance of.

Reproduce code:
---------------
              if (!$obj instanceof $relatedTable->getPhpName())
              {
                if (!isset($this->object_references[$relatedTable->getPhpName().'_'.$value]))
                {
                  throw new sfException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getPhpName()));
                }
                $value = $this->object_references[$relatedTable->getPhpName().'_'.$value]->getPrimaryKey();
              }


Expected result:
----------------
The instanceof operator should determine whether $obj is an instance of the class name returned by $relatedTable->getPhpName()

Actual result:
--------------
Parse error: syntax error, unexpected '(' in /home/jablko/public_html/qubit/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/propel/sfPropelData.class.php on line 133

Line 133 is the first line of the reproduce code: if (!$obj instanceof $relatedTable->getPhpName())

This also raises a parse error: if (!$obj instanceof $relatedPhpName = $relatedTable->getPhpName())

Parse error: syntax error, unexpected '=' in /home/jablko/public_html/qubit/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/propel/sfPropelData.class.php on line 133

However the following works:

              $relatedPhpName = $relatedTable->getPhpName();
              if (!$obj instanceof $relatedPhpName)
              {
                if (!isset($this->object_references[$relatedTable->getPhpName().'_'.$value]))
                {
                  throw new sfException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getPhpName()));
                }
                $value = $this->object_references[$relatedTable->getPhpName().'_'.$value]->getPrimaryKey();
              }


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-31 10:25 UTC] felipe@php.net
This is not a bug.

Actually, PHP only accepts:
... instanceof $var
... instanceof $obj->property->...
... instanceof className
... instanceof Foo::bar::...
 [2008-02-02 13:22 UTC] felipe@php.net
.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 14:01:37 2025 UTC