Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions Zend/tests/anon/015.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
anonymous class use global
--FILE--
<?php
$glow = 50;
new class use($glow) {
public function __construct() {
var_dump($this->glow);
}
};
?>
--EXPECT--
int(50)
19 changes: 19 additions & 0 deletions Zend/tests/anon/016.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
anonymous class use global again
--FILE--
<?php
$glow = 50;
function thing($glow) {
return new class use($glow) {
public function __construct() {
var_dump($this->glow);
}
};
}

thing(400);
thing(500);
?>
--EXPECT--
int(400)
int(500)
16 changes: 16 additions & 0 deletions Zend/tests/anon/017.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
anonymous class use private
--FILE--
<?php
$glow = 50;
new class use($glow) {
public function __construct() {
var_dump($this);
}
};
?>
--EXPECT--
object(class@anonymous)#1 (1) {
["glow":"class@anonymous":private]=>
int(50)
}
19 changes: 19 additions & 0 deletions Zend/tests/anon/018.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
anonymous class use ref
--FILE--
<?php
$glow = 50;
new class use(&$glow) {

public function __construct() {
var_dump($this->glow);
$this->glow *= 2;
var_dump($this->glow);
}
};
var_dump($glow);
?>
--EXPECT--
int(50)
int(100)
int(100)
21 changes: 21 additions & 0 deletions Zend/tests/anon/019.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
anonymous class use counted
--FILE--
<?php
$glow = "php7";
new class use(&$glow) {

public function __construct() {
var_dump($this->glow);
$this->glow .= " rocks";
var_dump($this->glow);
}
};

var_dump($glow);
?>
--EXPECT--
string(4) "php7"
string(10) "php7 rocks"
string(10) "php7 rocks"

28 changes: 28 additions & 0 deletions Zend/tests/anon/020.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
anonymous class use prop ref
--FILE--
<?php
$glow = "php7";

$thing = new class use(&$glow) {

public function __construct() {

new class use(&$this->glow) {

public function __construct() {
var_dump($this->glow);
$this->glow .= " rocks";
var_dump($this->glow);
}
};
}
};

var_dump($glow);
?>
--EXPECT--
string(4) "php7"
string(10) "php7 rocks"
string(10) "php7 rocks"

26 changes: 26 additions & 0 deletions Zend/tests/anon/021.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
anonymous class use prop no ref
--FILE--
<?php
$glow = "php7";

new class use($glow) {
public function __construct() {
new class use($this->glow) {
public function __construct() {
var_dump($this->glow);
$this->glow .= " rocks";
var_dump($this->glow);
}
};
}
};

var_dump($glow);
?>
--EXPECT--
string(4) "php7"
string(10) "php7 rocks"
string(4) "php7"


41 changes: 41 additions & 0 deletions Zend/tests/anon/022.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
anonymous class use prop object
--FILE--
<?php
$glow = new stdClass;
$glow->php7 = "php7";

new class use($glow) {
public function __construct() {
new class use($this->glow) {
public function __construct() {
var_dump($this->glow);
$this->glow->rocks = " rocks";
var_dump($this->glow);
}
};
}
};

var_dump($glow);
?>
--EXPECT--
object(stdClass)#1 (1) {
["php7"]=>
string(4) "php7"
}
object(stdClass)#1 (2) {
["php7"]=>
string(4) "php7"
["rocks"]=>
string(6) " rocks"
}
object(stdClass)#1 (2) {
["php7"]=>
string(4) "php7"
["rocks"]=>
string(6) " rocks"
}



43 changes: 43 additions & 0 deletions Zend/tests/anon/023.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
anonymous class use prop object member object
--FILE--
<?php
$glow = new stdClass;
$glow->php7 = new stdClass;

new class use($glow->php7) {
public function __construct() {
new class use($this->php7) {
public function __construct() {
var_dump($this->php7);
$this->php7->rocks = " rocks";
var_dump($this->php7);
var_dump($this);
}
};
}
};

var_dump($glow);
?>
--EXPECT--
object(stdClass)#2 (0) {
}
object(stdClass)#2 (1) {
["rocks"]=>
string(6) " rocks"
}
object(class@anonymous)#4 (1) {
["php7":"class@anonymous":private]=>
object(stdClass)#2 (1) {
["rocks"]=>
string(6) " rocks"
}
}
object(stdClass)#1 (1) {
["php7"]=>
object(stdClass)#2 (1) {
["rocks"]=>
string(6) " rocks"
}
}
28 changes: 28 additions & 0 deletions Zend/tests/anon/024.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
anonymous class use prop object member change acc allow
--FILE--
<?php
$glow = 10;

class Foo {
public function method() {
return $this->glow;
}
}

new class use($glow) {
public function __construct() {
$foo = new class extends Foo use($this->glow) {
protected $glow;
};

var_dump($foo->method());
}
};

var_dump($glow);
?>
--EXPECT--
int(10)
int(10)

12 changes: 12 additions & 0 deletions Zend/tests/anon/025.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
anonymous class cannot use variable twice
--FILE--
<?php
$glow = 10;

new class use($glow, $glow) {};
?>
--EXPECTF--
Fatal error: Cannot use property name glow twice in %s on line 4


18 changes: 18 additions & 0 deletions Zend/tests/anon/026.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
anonymous class cannot use variable twice
--FILE--
<?php
$glow = 10;

new class {
public function __construct() {
new class use($glow, $this->glow) {};
}
}


?>
--EXPECTF--
Fatal error: Cannot use property name glow twice in %s on line 6


6 changes: 5 additions & 1 deletion Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ZEND_API zend_ast *zend_ast_create_zval_ex(zval *zv, zend_ast_attr attr) {

ZEND_API zend_ast *zend_ast_create_decl(
zend_ast_kind kind, uint32_t flags, uint32_t start_lineno, zend_string *doc_comment,
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4
) {
zend_ast_decl *ast;

Expand All @@ -87,6 +87,7 @@ ZEND_API zend_ast *zend_ast_create_decl(
ast->child[1] = child1;
ast->child[2] = child2;
ast->child[3] = child3;
ast->child[4] = child4;

return (zend_ast *) ast;
}
Expand Down Expand Up @@ -472,6 +473,9 @@ static void zend_ast_destroy_ex(zend_ast *ast, zend_bool free) {
zend_ast_destroy_ex(decl->child[1], free);
zend_ast_destroy_ex(decl->child[2], free);
zend_ast_destroy_ex(decl->child[3], free);
if (decl->child[4]) {
zend_ast_destroy_ex(decl->child[4], free);
}
break;
}
default:
Expand Down
5 changes: 3 additions & 2 deletions Zend/zend_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum _zend_ast_kind {
ZEND_AST_NAME_LIST,
ZEND_AST_TRAIT_ADAPTATIONS,
ZEND_AST_USE,
ZEND_AST_ANON_USE,

/* 0 child nodes */
ZEND_AST_MAGIC_CONST = 0 << ZEND_AST_NUM_CHILDREN_SHIFT,
Expand Down Expand Up @@ -184,7 +185,7 @@ typedef struct _zend_ast_decl {
unsigned char *lex_pos;
zend_string *doc_comment;
zend_string *name;
zend_ast *child[4];
zend_ast *child[5];
} zend_ast_decl;

typedef void (*zend_ast_process_t)(zend_ast *ast);
Expand All @@ -197,7 +198,7 @@ ZEND_API zend_ast *zend_ast_create(zend_ast_kind kind, ...);

ZEND_API zend_ast *zend_ast_create_decl(
zend_ast_kind kind, uint32_t flags, uint32_t start_lineno, zend_string *doc_comment,
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4
);

ZEND_API zend_ast *zend_ast_create_list(uint32_t init_children, zend_ast_kind kind, ...);
Expand Down
Loading