|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-31 10:25 UTC] felipe@php.net
[2008-02-02 13:22 UTC] felipe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 13:00:02 2025 UTC |
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(); }