Skip to content

anon class objects #470

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

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
4eb55fe
part of mangled property names exposure solution
krakjoe Apr 19, 2013
51b81ba
part of mangled property names exposed solution
krakjoe Apr 19, 2013
df1aacd
part of mangled property names exposed solution
krakjoe Apr 19, 2013
9ba36d1
just send publics
krakjoe Apr 19, 2013
3383007
TSRM
krakjoe Apr 19, 2013
e337a85
use unmangled names
krakjoe Apr 19, 2013
836a5e5
testing out stacking error handlers
krakjoe Apr 22, 2013
16423c7
testing out stacking error handlers
krakjoe Apr 22, 2013
421fe79
testing out stacking error handlers
krakjoe Apr 22, 2013
10e2e8c
Merge branch 'master' of https://github.com/php/php-src
krakjoe Apr 22, 2013
c608896
reverse this
krakjoe Apr 22, 2013
07ef309
Merge branch 'master' of https://github.com/php/php-src
krakjoe Aug 5, 2013
625acc3
fix strangeness for pthreads
krakjoe Aug 12, 2013
e70489c
sensible check for onEnable ini mh
krakjoe Aug 12, 2013
cef10c7
correction
krakjoe Aug 12, 2013
7a715cd
Merge branch 'master' of https://github.com/krakjoe/php-src
krakjoe Aug 13, 2013
59bd2bd
anon class objects
krakjoe Sep 21, 2013
0570bce
prototype zend_do_create_anon_class in header
krakjoe Sep 22, 2013
0a2f96e
allow methods to return anon classes
krakjoe Sep 22, 2013
f4b3b55
cleanup patch:
krakjoe Sep 22, 2013
9aa3599
code paths fix, allow while () {new class{}} etc, re-using definition
krakjoe Sep 25, 2013
2f231ff
don't need these
krakjoe Sep 25, 2013
d8af087
tidy patch
krakjoe Sep 25, 2013
ad66245
fix for zts
krakjoe Sep 25, 2013
d9a1752
resolve last errors / inconsistencies in ZTS mode
krakjoe Sep 25, 2013
a084e59
some tests
krakjoe Sep 25, 2013
a629e04
allow extends $this
krakjoe Sep 25, 2013
dedecdd
drop the option to extend $this
krakjoe Sep 25, 2013
a97171d
make sensible test
krakjoe Sep 25, 2013
14eaa35
fix objects that implement interfaces failing on second attempt at ob…
krakjoe Sep 25, 2013
71d5cf9
correction
krakjoe Sep 26, 2013
aeee995
remove pointless stuff
krakjoe Sep 26, 2013
937e404
tidy
krakjoe Sep 26, 2013
e64f807
improve anonymous class name generation
krakjoe Sep 26, 2013
533905c
improve anon class name generation
krakjoe Sep 26, 2013
1d6013e
woops, that's from another patch
krakjoe Sep 26, 2013
ca1bd0a
remove
krakjoe Sep 27, 2013
899a2a8
super:: support
krakjoe Sep 27, 2013
c8c0bdb
more general static access
krakjoe Sep 27, 2013
43b6942
remove super::
krakjoe Sep 27, 2013
ce59d79
cleanup whitespace etc
krakjoe Sep 27, 2013
b8c26a0
cleanup ...
krakjoe Sep 27, 2013
68e8859
cleanup ...
krakjoe Sep 27, 2013
b48c993
cleanup ...
krakjoe Sep 27, 2013
7557e70
cleanup ...
krakjoe Sep 27, 2013
165ea21
cleanup ...
krakjoe Sep 27, 2013
113a52d
format parser in the normal way
krakjoe Sep 28, 2013
a49bcf6
fix namespacing issues
krakjoe Sep 28, 2013
c106cda
add test for namespaced anons
krakjoe Sep 28, 2013
26d021b
Merge branch 'master' of https://github.com/krakjoe/php-src
krakjoe Sep 28, 2013
e75bfbe
Merge branch 'master' of http://github.com/php/php-src
krakjoe Sep 28, 2013
1055b3f
more bc
krakjoe Sep 28, 2013
38592f0
more bc, passing Zend/tests
krakjoe Sep 28, 2013
1fd0eba
fix functions that declare anons inside namespaces outside of classes
krakjoe Sep 29, 2013
f880310
another test
krakjoe Sep 29, 2013
903bff5
avoid clashes in the global scope by using filename in class name
krakjoe Sep 29, 2013
b91a8d2
bring tests inline
krakjoe Sep 29, 2013
d6f7e2f
Merge branch 'master' of http://github.com/php/php-src
krakjoe Sep 29, 2013
f6e06ae
Merge branch 'anon_class_objects' of https://github.com/krakjoe/php-s…
krakjoe Sep 29, 2013
e9ab202
...
krakjoe Sep 29, 2013
28a4941
more precise
krakjoe Sep 29, 2013
1878372
...
krakjoe Sep 29, 2013
fb83ad7
...
krakjoe Sep 29, 2013
7bfbb33
...
krakjoe Sep 29, 2013
2e5bbd8
...
krakjoe Sep 29, 2013
7e17fa0
...
krakjoe Sep 29, 2013
e0d9c3b
...
krakjoe Sep 29, 2013
19b1dce
set extended attributes on class names where not present
krakjoe Sep 30, 2013
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
10 changes: 10 additions & 0 deletions Zend/tests/anon/001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
declare bare anonymous class
--FILE--
<?php
var_dump(new class{});
?>
--EXPECTF--
object(%s$$1)#%d (0) {
}

10 changes: 10 additions & 0 deletions Zend/tests/anon/002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
declare anonymous class extending another
--FILE--
<?php
var_dump(new class extends stdClass{});
?>
--EXPECTF--
object(%s$$1)#%d (0) {
}

54 changes: 54 additions & 0 deletions Zend/tests/anon/003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--TEST--
reusing anonymous classes
--FILE--
<?php
while (@$i++<10) {
var_dump(new class{
public function __construct($i) {
$this->i = $i;
}
}($i));
}
?>
--EXPECTF--
object(%s$$1)#1 (1) {
["i"]=>
int(1)
}
object(%s$$1)#1 (1) {
["i"]=>
int(2)
}
object(%s$$1)#1 (1) {
["i"]=>
int(3)
}
object(%s$$1)#1 (1) {
["i"]=>
int(4)
}
object(%s$$1)#1 (1) {
["i"]=>
int(5)
}
object(%s$$1)#1 (1) {
["i"]=>
int(6)
}
object(%s$$1)#1 (1) {
["i"]=>
int(7)
}
object(%s$$1)#1 (1) {
["i"]=>
int(8)
}
object(%s$$1)#1 (1) {
["i"]=>
int(9)
}
object(%s$$1)#1 (1) {
["i"]=>
int(10)
}

34 changes: 34 additions & 0 deletions Zend/tests/anon/004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
testing anonymous inheritance
--FILE--
<?php
class Outer {
protected $data;

public function __construct($data) {
$this->data = $data;
}

public function getArrayAccess() {
/* create a proxy object implementing array access */
return new class extends Outer implements ArrayAccess {
public function offsetGet($offset) { return $this->data[$offset]; }
public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); }
public function offsetUnset($offset) { unset($this->data[$offset]); }
public function offsetExists($offset) { return isset($this->data[$offset]); }
}($this->data);
}
}

$outer = new Outer(array(
rand(1, 100)
));

$proxy = $outer->getArrayAccess();

var_dump($proxy[0]);
?>
--EXPECTF--
int(%d)


39 changes: 39 additions & 0 deletions Zend/tests/anon/005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
testing reusing anons that implement an interface
--FILE--
<?php
class Outer {
protected $data;

public function __construct(&$data) {
/* array access will be implemented by the time we get to here */
$this->data = &$data;
}

public function getArrayAccess() {
/* create a child object implementing array access */
/* this grants you access to protected methods and members */
return new class extends Outer implements ArrayAccess {
public function offsetGet($offset) { return $this->data[$offset]; }
public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); }
public function offsetUnset($offset) { unset($this->data[$offset]); }
public function offsetExists($offset) { return isset($this->data[$offset]); }
}($this->data);
}
}

$data = array(
rand(1, 100),
rand(2, 200)
);
$outer = new Outer($data);
$proxy = $outer->getArrayAccess();

unset($proxy[0]);
var_dump(@$outer->getArrayAccess()[0]);
?>
--EXPECT--
NULL



18 changes: 18 additions & 0 deletions Zend/tests/anon/006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
testing anons inside namespaces
--FILE--
<?php
namespace lone {
$hello = new class{} ;
}

namespace {
var_dump ($hello);
}
?>
--EXPECTF--
object(%s$$1)#1 (0) {
}



26 changes: 26 additions & 0 deletions Zend/tests/anon/007.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
testing anons in functions outside of classes in namespaces
--FILE--
<?php
namespace lone {
function my_factory() {
return new class{};
}

class Outer {

public function __construct() {
var_dump(
my_factory());
}
}

new Outer();
}
?>
--EXPECT--
object(my_factory$$1)#2 (0) {
}



1 change: 1 addition & 0 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS
compiler_globals->static_members_table = NULL;
}
compiler_globals->script_encoding_list = NULL;
compiler_globals->anon_class_id = 0L;
}
/* }}} */

Expand Down
Loading