Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform variable syntax #686

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
95a3a12
Change precedence of $ operator
nikic May 30, 2014
e2be2ce
Temporarily disable complex variables in new expressions
nikic May 30, 2014
46e35e3
Get rid of base_variable_with_function_calls
nikic May 30, 2014
b8b3b35
Use recursion for property fetches
nikic May 30, 2014
a8c1595
LTR static member access
nikic May 30, 2014
667f840
Recursive definition for object proprety fetches
nikic May 30, 2014
e89958a
Make function calls directly callable
nikic May 30, 2014
067fca0
Remove reference_variable indirection
nikic May 30, 2014
295d07e
Reintroduce new expression dereferencing
nikic May 30, 2014
87f8e75
Cleanup old grammar rules
nikic May 30, 2014
5712f0e
Minor cleanup
nikic May 30, 2014
46a2ca8
Generalize expression dereferencing
nikic May 30, 2014
75c0db1
Integrate combined scalar as dereferencable
nikic May 30, 2014
ff475e9
Allow arrays + object access for new expressions
nikic May 30, 2014
c5920af
Update two tests with new semantics
nikic May 30, 2014
c29d3b6
Update another test
nikic May 30, 2014
fcf42d8
Remove object_stack (mostly)
nikic May 31, 2014
8a65c3b
Remove now unnecessary code in begin_method_call
nikic May 31, 2014
f48241f
Generalize static access syntax
nikic May 31, 2014
4ec505f
Add two initial tests
nikic May 31, 2014
64f80b3
Introduce dereferencable_scalar to simplify future additions
nikic May 31, 2014
fd85f77
Fix previous commit
nikic May 31, 2014
64e4c9e
Support directly calling closure
nikic May 31, 2014
c53a7ea
Property handle calls on [] and '' consts/tmps
nikic May 31, 2014
f0ac7f7
Properly handle property read on const/tmp
nikic May 31, 2014
72b5e0c
Add another static member access test
nikic May 31, 2014
5c2120b
Forbid writing to temporary expressions
nikic May 31, 2014
96b32ec
Support isset() on temporaries
nikic May 31, 2014
8515b96
Handle FUNC_ARG fetches on temporaries
nikic May 31, 2014
8d7f5a4
Remove duplication
nikic May 31, 2014
f4a11b6
Merge and rename to member_name
nikic May 31, 2014
e4e42df
Allow only simple variables with global keyword
nikic Jun 4, 2014
c8aa51f
Accept static member fetch in new variable (BC)
nikic Jun 6, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/024.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var_dump($a++);
var_dump(++$b);
var_dump($a->$b);
var_dump($a->$b);
var_dump($a->$b->$c[1]);
var_dump($a->$b->{$c[1]});

?>
--EXPECTF--
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug27669.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Bug #27669 (PHP 5 didn't support all possibilities for calling static methods dy
}
}
$y[0] = 'hello';
A::$y[0]();
A::{$y[0]}();
?>
===DONE===
--EXPECTF--
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/isset_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var_dump(isset($a[0]->a));

var_dump(isset($c[0][1][2]->a->b->c->d));

var_dump(isset(${$a}->{$b->$c[$d]}));
var_dump(isset(${$a}->{$b->{$c[$d]}}));

var_dump(isset($GLOBALS));

Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/isset_003_2_4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var_dump(isset($a[0]->a));

var_dump(isset($c[0][1][2]->a->b->c->d));

var_dump(isset(${$a}->{$b->$c[$d]}));
var_dump(isset(${$a}->{$b->{$c[$d]}}));

var_dump(isset($GLOBALS));

Expand Down
10 changes: 10 additions & 0 deletions Zend/tests/varSyntax/globalNonSimpleVariableError.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Global keyword only accepts simple variables
--FILE--
<?php

global $$foo->bar;

?>
--EXPECTF--
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' in %s on line %d
53 changes: 53 additions & 0 deletions Zend/tests/varSyntax/indirectFcall.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--TEST--
Indirect function calls
--FILE--
<?php

function id($x = 'id') { return $x; }

var_dump(0);

id('var_dump')(1);
id('id')('var_dump')(2);
id('id')('id')('var_dump')(3);
id()()('var_dump')(4);

id(['udef', 'id'])[1]()('var_dump')(5);
(id((object) ['a' => 'id', 'b' => 'udef'])->a)()()()()('var_dump')(6);

$id = function($x) { return $x; };

$id($id)('var_dump')(7);

(function($x) { return $x; })('id')('var_dump')(8);

($f = function($x = null) use (&$f) {
return $x ?: $f;
})()()()('var_dump')(9);

class Test {
public static function id($x = [__CLASS__, 'id']) { return $x; }
}

$obj = new Test;
[$obj, 'id']()('id')($id)('var_dump')(10);
['Test', 'id']()()('var_dump')(11);
'id'()('id')('var_dump')(12);
('i' . 'd')()('var_dump')(13);

?>
--EXPECT--
int(0)
int(1)
int(2)
int(3)
int(4)
int(5)
int(6)
int(7)
int(8)
int(9)
int(10)
int(11)
int(12)
int(13)
26 changes: 26 additions & 0 deletions Zend/tests/varSyntax/issetOnTemp.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
isset() can be used on dereferences of temporary expressions
--FILE--
<?php

var_dump(isset([0, 1][0]));
var_dump(isset(([0, 1] + [])[0]));
var_dump(isset([[0, 1]][0][0]));
var_dump(isset(([[0, 1]] + [])[0][0]));
var_dump(isset(((object) ['a' => 'b'])->a));
var_dump(isset(['a' => 'b']->a));
var_dump(isset("str"->a));
var_dump(isset((['a' => 'b'] + [])->a));
var_dump(isset((['a' => 'b'] + [])->a->b));

?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
39 changes: 39 additions & 0 deletions Zend/tests/varSyntax/newVariable.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Variable as class name for new expression
--FILE--
<?php

$className = 'stdClass';
$array = ['className' => 'stdClass'];
$obj = (object) ['className' => 'stdClass'];

class Test {
public static $className = 'stdClass';
}
$test = 'Test';
$weird = [0 => (object) ['foo' => 'Test']];

var_dump(new $className);
var_dump(new $array['className']);
var_dump(new $array{'className'});
var_dump(new $obj->className);
var_dump(new Test::$className);
var_dump(new $test::$className);
var_dump(new $weird[0]->foo::$className);

?>
--EXPECTF--
object(stdClass)#%d (0) {
}
object(stdClass)#%d (0) {
}
object(stdClass)#%d (0) {
}
object(stdClass)#%d (0) {
}
object(stdClass)#%d (0) {
}
object(stdClass)#%d (0) {
}
object(stdClass)#%d (0) {
}
20 changes: 20 additions & 0 deletions Zend/tests/varSyntax/parenthesesDeref.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Dereferencing expression parentheses
--FILE--
<?php

$array = [&$array, 1];
var_dump(($array)[1]);
var_dump((($array[0][0])[0])[1]);

var_dump(((object) ['a' => 0, 'b' => 1])->b);

$obj = (object) ['a' => 0, 'b' => ['var_dump', 1]];
(clone $obj)->b[0](1);

?>
--EXPECT--
int(1)
int(1)
int(1)
int(1)
10 changes: 10 additions & 0 deletions Zend/tests/varSyntax/propertyOfStringError.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot take property of a string
--FILE--
<?php

"foo"->bar;

?>
--EXPECTF--
Notice: Trying to get property of non-object in %s on line %d
37 changes: 37 additions & 0 deletions Zend/tests/varSyntax/staticMember.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Static member access
--FILE--
<?php

class A {
public static $b = 0;
public static $c = [0, 1];
public static $A_str = 'A';
}

$A_str = 'A';
$A_obj = new A;
$b_str = 'b';
$c_str = 'c';

var_dump(A::$b);
var_dump($A_str::$b);
var_dump($A_obj::$b);
var_dump(('A' . '')::$b);
var_dump('A'::$b);
var_dump('A'[0]::$b);
var_dump(A::$$b_str);
var_dump(A::$$c_str[1]);
var_dump(A::$A_str::$b);

?>
--EXPECT--
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(1)
int(0)
11 changes: 11 additions & 0 deletions Zend/tests/varSyntax/tempDimFetchByRefError.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Passing a dimention fetch on a temporary by reference is not allowed
--FILE--
<?php

$fn = function(&$ref) {};
$fn([0, 1][0]);

?>
--EXPECTF--
Fatal error: Cannot use temporary expression in write context in %s on line %d
11 changes: 11 additions & 0 deletions Zend/tests/varSyntax/tempPropFetchByRefError.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Passing a property fetch on a temporary by reference is not allowed
--FILE--
<?php

$fn = function(&$ref) {};
$fn([0, 1]->prop);

?>
--EXPECTF--
Fatal error: Cannot use temporary expression in write context in %s on line %d
10 changes: 10 additions & 0 deletions Zend/tests/varSyntax/writeToTempExpr.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Writing to a temporary expression is not allowed
--FILE--
<?php

[0, 1][0] = 1;

?>
--EXPECTF--
Fatal error: Cannot use temporary expression in write context in %s on line %d
3 changes: 0 additions & 3 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,6 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
zend_stack function_call_stack;
zend_stack switch_cond_stack;
zend_stack foreach_copy_stack;
zend_stack object_stack;
zend_stack declare_stack;
zend_stack list_stack;
zend_stack context_stack;
Expand Down Expand Up @@ -1192,7 +1191,6 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
SAVE_STACK(function_call_stack);
SAVE_STACK(switch_cond_stack);
SAVE_STACK(foreach_copy_stack);
SAVE_STACK(object_stack);
SAVE_STACK(declare_stack);
SAVE_STACK(list_stack);
SAVE_STACK(context_stack);
Expand All @@ -1218,7 +1216,6 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
RESTORE_STACK(function_call_stack);
RESTORE_STACK(switch_cond_stack);
RESTORE_STACK(foreach_copy_stack);
RESTORE_STACK(object_stack);
RESTORE_STACK(declare_stack);
RESTORE_STACK(list_stack);
RESTORE_STACK(context_stack);
Expand Down
Loading