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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 17:01:29 2024 UTC