This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This fixes the "bug" in PHP's grammar where you aren't allowed to use the [...] operator on the return value of a function. It rewrites all instances which would be syntax errors into ##__xhp_idx($arr, $index)##. __xhp_idx is implemented in ext.cpp in C and is probably faster than the idx we made in PHP. It behaves exactly as the [...] operator would. If you want to ignore undefined index warnings you can do ##@foo()['etc']## and the @ will only apply to the __xhp_idx call. One thing to watch out for is that each chained [...] on the end of a function is a function call. So if you're doing something like ##foo()['bar']['etc']['muk']## you get 3 calls to __xhp_idx. TODO: Add ini entry to disable this feature (only need to set a flag). Reviewed By: dweatherford Test Plan: marcel@dev050 ~/xhp $ cat honk.php <?php error_reporting(E_ALL); function foo() { return array( 'bar' => 'etc', ); } echo foo()['bar'] . "\n"; echo foo()['etc']; echo @foo()['etc']; marcel@dev050 ~/xhp $ php honk.php etc PHP Notice: Undefined index: etc in /home/marcel/xhp/honk.php on line 10 I also ran the whole codebase through xhpize to make sure no lines were getting rewritten that didn't need it. Revert: OK DiffCamp Revision: 66576
- Loading branch information
Marcel Laverdet
committed
Oct 2, 2009
1 parent
8e72216
commit 86fb887
Showing
5 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters