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

[POC] Support calling global functions from constant expressions #12

Closed
wants to merge 126 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
ba82e18
Allow empty needle in mb_strrchr()
Girgias Jan 25, 2020
300d4df
Add mention about empty needles for strrch() functions in UPGRADING […
Girgias Jan 25, 2020
a1f2f8f
Fixed bug #79080 [ci skip]
Girgias Jan 25, 2020
86f463c
Merge branch 'PHP-7.3' into PHP-7.4
Girgias Jan 25, 2020
12e903d
Merge branch 'PHP-7.4'
Girgias Jan 25, 2020
52d0783
Upgrade bundled PCRE2 to 10.34
weltling Jan 21, 2020
378010a
Fix bundled PCRE2 compilation on ARM64
weltling Jan 25, 2020
b836d9c
Add CURLOPT CURLOPT_HTTP09_ALLOWED available since 7.64.0
Jan 26, 2020
41e1891
Merge branch 'PHP-7.3' into PHP-7.4
cmb69 Jan 26, 2020
2fe8666
Merge branch 'PHP-7.4'
cmb69 Jan 26, 2020
9f4d1b9
Fix typo [ci skip]
staabm Jan 25, 2020
3f67798
[skip ci] Fix typos in NEWS
TysonAndre Jan 26, 2020
fd08f06
Fix bug #78323: Code 0 is returned on invalid options
diafour Jan 17, 2020
1cccbb8
Merge branch 'PHP-7.3' into PHP-7.4
nikic Jan 27, 2020
16f194c
Merge branch 'PHP-7.4'
nikic Jan 27, 2020
ea1b878
Fix #78969 Make PASSWORD_DEFAULT match PASSWORD_BCRYPT instead of bei…
kocsismate Jan 22, 2020
d6a6a60
Merge branch 'PHP-7.4'
kocsismate Jan 27, 2020
8dd91f5
Remove state pointer argument from php_strip_tags
nikic Jan 27, 2020
5215f07
- bump zip extension version to 1.15.6
remicollet Jan 27, 2020
cb1b26a
Merge branch 'PHP-7.4'
remicollet Jan 27, 2020
9a76a2a
Convert some warnings into ValueErrors in the standard file extension
Girgias Dec 11, 2019
5f92a08
Convert ZEND_ECHO operand to string after sccp
TysonAndre Jan 26, 2020
412b476
Fix #79172: STRUCT_OFFSET() relies on undefined behavior
cmb69 Jan 28, 2020
7e5a8d9
Merge branch 'PHP-7.4'
cmb69 Jan 28, 2020
136f51f
Fix #76584: PharFileInfo::decompress not working
cmb69 Jan 26, 2020
e197f65
Merge branch 'PHP-7.3' into PHP-7.4
cmb69 Jan 28, 2020
9a5ea0d
Merge branch 'PHP-7.4'
cmb69 Jan 28, 2020
1146bdb
Fixed bug #78989
nikic Jan 28, 2020
3bae179
Merge branch 'PHP-7.4'
nikic Jan 28, 2020
ac9a265
- bump zip extension version to 1.16.0 - add ZipArchive::setMtimeName…
remicollet Jan 28, 2020
521c405
Don't index NULL pointer when fetching non-existent constant
nikic Jan 28, 2020
c59219d
Perform map ptr base arithmetic through uintptr_t
nikic Jan 28, 2020
d91abf7
zip: fix lib check
remicollet Jan 28, 2020
2342c06
Throw an exception if default_dir not set, but required
nikic Jan 28, 2020
648f16c
Fix rel_date leak on DateInterval construction failure
nikic Jan 28, 2020
d705276
Enable support for LIBZIP_VERSION
cmb69 Jan 28, 2020
3b9e822
Merge branch 'PHP-7.4'
cmb69 Jan 28, 2020
b0d7b12
Make BG(syslog_device) per request
nikic Jan 28, 2020
7db3a51
Only fetch to_encoding once in mb_convert_encoding()
nikic Jan 28, 2020
d91b166
Avoid shift UB for large arrays
nikic Jan 28, 2020
addc3c9
Fix #79174: cookie values with spaces fail to round-trip
cmb69 Jan 28, 2020
0563dfe
Merge branch 'PHP-7.4'
cmb69 Jan 28, 2020
8a5bc8c
Fix mysqli_get_warnings() with multi queries
nikic Jan 28, 2020
7d3a6e7
Merge branch 'PHP-7.4'
nikic Jan 28, 2020
9fcaf25
Fix memory leak in mb_str_split
nikic Jan 28, 2020
38d205a
Merge branch 'PHP-7.4'
nikic Jan 28, 2020
d39edeb
Fix #78666 mysqli_options generates Warning on var_dump()
kocsismate Jan 24, 2020
cffff1f
Merge branch 'PHP-7.4'
kocsismate Jan 28, 2020
ce44cd3
Fixed bug #79092 (Building with clang+lld-9 results in a broken PHP b…
dstogov Jan 29, 2020
8bdce8e
Merge branch 'PHP-7.4'
dstogov Jan 29, 2020
5265fab
Use "%define parse.error verbose"
akimd Jan 28, 2020
a73df8e
Merge branch 'PHP-7.4'
nikic Jan 29, 2020
91f8787
Fix recovery of large entities in mb_decode_numericentity()
nikic Jan 29, 2020
bc32cce
Merge branch 'PHP-7.4'
nikic Jan 29, 2020
5589bf4
Fix length inconsistency in mb_convert_encoding
nikic Jan 29, 2020
083bbf5
Merge branch 'PHP-7.4'
nikic Jan 29, 2020
7d2ef3d
Fix datatype
weltling Jan 29, 2020
392ad20
Fix use of mb_ereg_search_getregs() after invalid pattern
nikic Jan 29, 2020
b3f07af
Merge branch 'PHP-7.3' into PHP-7.4
nikic Jan 29, 2020
42e22a2
Merge branch 'PHP-7.4'
nikic Jan 29, 2020
6352e9a
Backport 7d2ef3d2e540885dec26d91dad061bff1621ad07 into 7.4
weltling Jan 29, 2020
92df876
Merge branch 'PHP-7.4'
weltling Jan 29, 2020
bdcfdd4
zip: more constants
remicollet Jan 29, 2020
272698d
Merge branch 'PHP-7.4'
remicollet Jan 29, 2020
b8d635c
zip extension version is now 1.16.1
remicollet Jan 29, 2020
560ff97
Reset MBREX(search_re) in RSHUTDOWN
nikic Jan 29, 2020
085371b
Merge branch 'PHP-7.3' into PHP-7.4
nikic Jan 29, 2020
22d2a80
Merge branch 'PHP-7.4'
nikic Jan 29, 2020
18599f9
Better overflow check for entity decoding
nikic Jan 29, 2020
b2c8abe
Merge branch 'PHP-7.4'
nikic Jan 29, 2020
a62c06c
Fix mb_ord() crash if internal encoding not supported
nikic Jan 29, 2020
acc616c
Merge branch 'PHP-7.3' into PHP-7.4
nikic Jan 29, 2020
2e97ae9
Merge branch 'PHP-7.4'
nikic Jan 29, 2020
dda67d3
Enable ZipArchive::setMtime(Name|Index) on Windows
cmb69 Jan 29, 2020
9aadcb1
Restore digit check in mb_decode_numericentity()
nikic Jan 29, 2020
4346576
Fix shift ub in mbstring
nikic Jan 28, 2020
7d170eb
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
1468484
Fix #74063: NumberFormatter fails after retrieval from session
cmb69 Jan 29, 2020
429f194
Fix UAF in is_callable() and allocated trampoline
nikic Jan 30, 2020
98deece
Reset trampoline on executor startup
nikic Jan 30, 2020
cb7b210
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
472fc3a
Fix leak in DatePeriod construction with invalid format
nikic Jan 30, 2020
6ccd675
Add SKIPIF to test requiring mbregex
nikic Jan 30, 2020
a73f98e
Merge branch 'PHP-7.3' into PHP-7.4
nikic Jan 30, 2020
7c34d73
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
68596ed
Fix copying of functions in variance obligations
nikic Jan 30, 2020
d5dd46f
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
24a3d0d
Update test for warning -> fatal error change
nikic Jan 30, 2020
494615f
Fix leak in DateTimeImmutable::modify()
nikic Jan 30, 2020
187f359
Merge branch 'PHP-7.3' into PHP-7.4
nikic Jan 30, 2020
0078727
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
8226e70
Fix #70078: XSL callbacks with nodes as parameter leak memory
cmb69 Jan 29, 2020
dfbeee0
Merge branch 'PHP-7.3' into PHP-7.4
cmb69 Jan 30, 2020
2dc5077
Merge branch 'PHP-7.4'
cmb69 Jan 30, 2020
01d30f8
Fix DatePeriod property handling with indirect modification
nikic Jan 30, 2020
a66e226
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
be7eab3
Fix live range calculation for FE_FETCH
nikic Jan 30, 2020
38e2762
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
f70b552
Fixed bug #79193
nikic Jan 30, 2020
b33697d
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
ca8657a
Initialize SplFixedArray elements to NULL instead of UNDEF
nikic Jan 30, 2020
f0f5c41
fix cross compilation failure due to size_t typecast in define
pmjdebruijn Jan 30, 2020
981fdd9
Merge branch 'PHP-7.4'
nikic Jan 30, 2020
4537138
Revert "Make BG(syslog_device) per request"
nikic Jan 30, 2020
5bf6aed
Promote mysqli warnings to exceptions
kocsismate Jan 5, 2020
176ec97
Add NEWS entry for new ReflectionProperty methods.
beberlei Jan 30, 2020
db7193f
Fixed bug #79094 (Crashing when running recursion function)
dstogov Jan 31, 2020
7ebf1d4
Merge branch 'PHP-7.4'
dstogov Jan 31, 2020
7e7a85e
Fixed JIT part for bug #79094
dstogov Jan 31, 2020
3af1cee
add ZipArchive::registerProgressCallback and ZipArchive::registerCanc…
remicollet Jan 30, 2020
b915d68
Zip: version is now 1.17.0
remicollet Jan 31, 2020
37d0f7d
Use "%empty" in the parsers, instead of comments
akimd Jan 30, 2020
ef1e489
Fix bug #76047
nikic Jan 31, 2020
d422478
Merge branch 'PHP-7.3' into PHP-7.4
nikic Jan 31, 2020
ec0ce49
Merge branch 'PHP-7.4'
nikic Jan 31, 2020
d8a1e3d
Fix JIT as well
nikic Jan 31, 2020
08d2d92
Export zend_dump_op() and add ZEND_DUMP_NUMERIC_OPLINES flag to print…
dstogov Jan 31, 2020
6b862e8
These EG(current_execute_data) = EX(prev_execute_data) assignments ar…
dstogov Jan 31, 2020
2b279b4
We don't need "safe" destruction anymore
dstogov Jan 31, 2020
ee87e86
inline by hand to avoid uninitialized variable warning
Jan 29, 2020
8b36be2
Fix indentation and whitespaces in tests
kocsismate Jan 31, 2020
19222b8
Fix var_dump test
kocsismate Jan 31, 2020
b97c9dc
Added opcache extension to inis
PeeHaa Jan 31, 2020
2127a37
Bison: enable all the warnings and fix them
akimd Feb 1, 2020
4cbffd8
Clean up the generation of the parsers
akimd Feb 1, 2020
096c2ff
[POC] Support calling functions from constant expressions
TysonAndre Jan 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 10 additions & 5 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PHP NEWS
(Nikita)
. Fixed bug #49555 (Fatal error "Function must be a string" message should be
renamed). (Nikita)
. Fixed bug #70839 (Convertion optional argument to variadic forbidden by LSP
. Fixed bug #70839 (Converting optional argument to variadic forbidden by LSP
checks). (Nikita)

- CURL:
Expand All @@ -19,7 +19,7 @@ PHP NEWS
- Date:
. Fixed bug #65547 (Default value for sunrise/sunset zenith still wrong).
(cmb)
. Fixed bug #69044 (discrepency between time and microtime). (krakjoe)
. Fixed bug #69044 (discrepancy between time and microtime). (krakjoe)

- DOM:
. Add property DOMXPath::$registerNodeNamespaces and constructor argument
Expand Down Expand Up @@ -57,7 +57,7 @@ PHP NEWS
. Fixed #60594 (mysqlnd exposes 160 lines of stats in phpinfo). (PeeHaa)

- OpCache:
. Fixed bug #78654 (Incorrectly computed opcache checksum on files with
. Fixed bug #78654 (Incorrectly computed opcache checksum on files with
non-ascii characters). (mhagstrand)

- PCRE:
Expand All @@ -79,8 +79,10 @@ PHP NEWS
. Fixed bug #77805 (phpdbg build fails when readline is shared). (krakjoe)

- Reflection:
. Fixed bug #78697 (ReflectionClass::implementsInterface - inaccurate error
. Fixed bug #78697 (ReflectionClass::implementsInterface - inaccurate error
message with traits). (villfa)
. Implement ReflectionProperty::hasDefaultValue and
Reflection::getDefaultValue (beberlei)

- Session:
. Fixed bug #78624 (session_gc return value for user defined session
Expand Down Expand Up @@ -113,10 +115,13 @@ PHP NEWS
. Fixed bug #76874 (xml_parser_free() should never leak memory). (Nikita)

- XMLWriter:
. Changed functions to accept/return XMKWriter objects instead of resources.
. Changed functions to accept/return XMLWriter objects instead of resources.
(cmb)

- Zip:
. Fixed bug #72374 (remove_path strips first char of filename). (tyage)
. Add ZipArchive::setMtimeName and ZipArchive::setMtimeIndex methods. (Remi)
. Add ZipArchive::setProgressCallback method (since libzip 1.3.0). (Remi)
. Add ZipArchive::setCancelCallback method (since libzip 1.6.0). (Remi)

<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
9 changes: 5 additions & 4 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ PHP 8.0 UPGRADE NOTES
. A non-string pattern argument to mb_ereg_replace() will now be interpreted
as a string instead of an ASCII codepoint. The previous behavior may be
restored with an explicit call to chr().
. The needle argument for mb_strpos(), mb_strrpos(), mb_stripos(), mb_strripos(), mb_strstr() and mb_stristr()
can now be empty.
. The needle argument for mb_strpos(), mb_strrpos(), mb_stripos(), mb_strripos(),
mb_strstr(), mb_stristr(), mb_strrchr() and mb_strrichr() can now be empty.
. The $is_hex parameter, which was not used internally, has been removed from
mb_decode_numericentity().
. The legacy behaviour of passing the encoding as the third argument instead of an offset for the mb_strrpos
Expand Down Expand Up @@ -286,7 +286,8 @@ PHP 8.0 UPGRADE NOTES
string. Previously non-string needles were interpreted as an ASCII code
point. An explicit call to chr() can be used to restore the previous
behavior.
. The needle argument for strpos(), strrpos(), stripos(), strripos(), strstr() and stristr() can now be empty.
. The needle argument for strpos(), strrpos(), stripos(), strripos(), strstr(),
stristr() and strrchr() can now be empty.
. The length argument for substr(), substr_count(), substr_compare(), and
iconv_substr() can now be null. Null values will behave as if no length
argument was provided and will therefore return the remainder of the string
Expand Down Expand Up @@ -351,7 +352,7 @@ PHP 8.0 UPGRADE NOTES
. Added WeakMap.
RFC: https://wiki.php.net/rfc/weak_maps
. Added ValueError class.
. Any number of function parameters may not be replaced by a variadic
. Any number of function parameters may now be replaced by a variadic
argument, as long as the types are compatible. For example, the following
code is now allowed:

Expand Down
4 changes: 2 additions & 2 deletions Zend/Makefile.frag
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $(srcdir)/zend_language_parser.c: $(srcdir)/zend_language_parser.y
# Tweak zendparse to be exported through ZEND_API. This has to be revisited once
# bison supports foreign skeletons and that bison version is used. Read
# https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md for more.
@$(YACC) -p zend -v -d $(srcdir)/zend_language_parser.y -o $@
@$(YACC) $(YFLAGS) -v -d $(srcdir)/zend_language_parser.y -o $@
@$(SED) -e 's,^int zendparse\(.*\),ZEND_API int zendparse\1,g' < $@ \
> [email protected] && \
mv [email protected] $@
Expand All @@ -27,7 +27,7 @@ $(srcdir)/zend_language_parser.c: $(srcdir)/zend_language_parser.y

$(srcdir)/zend_ini_parser.h: $(srcdir)/zend_ini_parser.c
$(srcdir)/zend_ini_parser.c: $(srcdir)/zend_ini_parser.y
@$(YACC) -p ini_ -v -d $(srcdir)/zend_ini_parser.y -o $@
$(YACC) $(YFLAGS) -v -d $(srcdir)/zend_ini_parser.y -o $@

$(srcdir)/zend_ini_scanner.c: $(srcdir)/zend_ini_scanner.l
@(cd $(top_srcdir); $(RE2C) $(RE2C_FLAGS) --no-generation-date --case-inverted -cbdFt Zend/zend_ini_scanner_defs.h -oZend/zend_ini_scanner.c Zend/zend_ini_scanner.l)
Expand Down
5 changes: 2 additions & 3 deletions Zend/tests/bug52361.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ try {
--EXPECTF--
1. Exception: aaa in %sbug52361.php:5
Stack trace:
#0 %sbug52361.php(13): aaa->__destruct()
#1 %sbug52361.php(16): bbb()
#2 {main}
#0 %sbug52361.php(16): aaa->__destruct()
#1 {main}
2. Exception: bbb in %sbug52361.php:13
Stack trace:
#0 %sbug52361.php(16): bbb()
Expand Down
68 changes: 68 additions & 0 deletions Zend/tests/bug76047.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
--TEST--
Bug #76047: Use-after-free when accessing already destructed backtrace arguments
--FILE--
<?php

class Vuln {
public $a;
public function __destruct() {
unset($this->a);
$backtrace = (new Exception)->getTrace();
var_dump($backtrace);
}
}

function test($arg) {
$arg = str_shuffle(str_repeat('A', 79));
$vuln = new Vuln();
$vuln->a = $arg;
}

function test2($arg) {
$$arg = 1; // Trigger symbol table
$arg = str_shuffle(str_repeat('A', 79));
$vuln = new Vuln();
$vuln->a = $arg;
}

test('x');
test2('x');

?>
--EXPECTF--
array(1) {
[0]=>
array(6) {
["file"]=>
string(%d) "%s"
["line"]=>
int(%d)
["function"]=>
string(10) "__destruct"
["class"]=>
string(4) "Vuln"
["type"]=>
string(2) "->"
["args"]=>
array(0) {
}
}
}
array(1) {
[0]=>
array(6) {
["file"]=>
string(%d) "%s"
["line"]=>
int(%d)
["function"]=>
string(10) "__destruct"
["class"]=>
string(4) "Vuln"
["type"]=>
string(2) "->"
["args"]=>
array(0) {
}
}
}
1 change: 0 additions & 1 deletion Zend/tests/bug78973.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ test(new class {
?>
--EXPECTF--
#0 class@anonymous->__destruct() called at [%s:%d]
#1 test() called at [%s:%d]
15 changes: 15 additions & 0 deletions Zend/tests/call_in_const/class_const01.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Can call internal functions from class constants
--FILE--
<?php
class Example {
const X = sprintf("Hello, %s\n", "World");

public static function main() {
echo "X is " . self::X . "\n";
}
}
Example::main();
?>
--EXPECT--
X is Hello, World
37 changes: 37 additions & 0 deletions Zend/tests/call_in_const/class_const02.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Can call internal functions from class constants
--FILE--
<?php
function normalize_keys(array $x) {
// Should only invoke normalize_keys once
echo "Normalizing the keys\n";
$result = [];
foreach ($x as $k => $value) {
$result["prefix_$k"] = $value;
}
return $result;
}
class Example {
const X = [
'key1' => 'value1',
'key2' => 'value2',
];
const Y = array_flip(self::X);
const Z = normalize_keys(self::Y);
}
var_export(Example::Z);
var_export(Example::Z);
var_export(Example::Y);
?>
--EXPECT--
Normalizing the keys
array (
'prefix_value1' => 'key1',
'prefix_value2' => 'key2',
)array (
'prefix_value1' => 'key1',
'prefix_value2' => 'key2',
)array (
'value1' => 'key1',
'value2' => 'key2',
)
10 changes: 10 additions & 0 deletions Zend/tests/call_in_const/global_const01.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Can call internal functions from global constants
--FILE--
<?php
const NIL = var_export(null, true);

echo "NIL is " . NIL . "\n";
?>
--EXPECT--
NIL is NULL
14 changes: 14 additions & 0 deletions Zend/tests/call_in_const/global_const02.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Cannot declare constants with function calls that contain objects
--FILE--
<?php
function make_object_array() {
return [new stdClass()];
}
const OBJECT_VALUES = make_object_array();
?>
--EXPECTF--
Fatal error: Uncaught Error: Calls in constants may only evaluate to scalar values, arrays or resources in %s:5
Stack trace:
#0 {main}
thrown in %s on line 5
24 changes: 24 additions & 0 deletions Zend/tests/call_in_const/param_defaults.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Can call internal functions from parameter default
--FILE--
<?php
function evaluated_user_function() {
// NOTE: PHP only caches non-refcounted values in the RECV_INIT value,
// meaning that if the returned value is dynamic, this will get called every time.
// TODO: Would it be worth it to convert refcounted values to immutable values?
echo "Evaluating default\n";
return sprintf("%s default", "Dynamic");
}
function test_default($x = evaluated_user_function()) {
echo "x is $x\n";
}
test_default();
test_default(2);
test_default();
?>
--EXPECT--
Evaluating default
x is Dynamic default
x is 2
Evaluating default
x is Dynamic default
25 changes: 25 additions & 0 deletions Zend/tests/call_in_const/param_ref.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Warn when calling function expecting a reference as an argument
--INI--
error_reporting=E_ALL
--FILE--
<?php
class Example {
const VALUES = [];
const IS_MATCH = preg_match('/test/', 'testing');
const IS_MATCH_V2 = preg_match('/test/', 'testing', self::VALUES);

public static function main() {
echo "X is " . self::X . "\n";
}
}
var_dump(Example::IS_MATCH);
var_dump(Example::IS_MATCH_V2);
var_dump(Example::VALUES);
--EXPECTF--
int(1)

Warning: Parameter 3 to preg_match() expected to be a reference, value given in %s on line 12
int(1)
array(0) {
}
36 changes: 36 additions & 0 deletions Zend/tests/call_in_const/property_default01.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Can call user-defined functions from defaults of static properties
--FILE--
<?php
namespace NS;

function log_call($arg) {
echo "log_call(" . var_export($arg, true) . ")\n";
return $arg;
}

class MyClass {
public static $DEBUG = log_call(true);
public static $DEBUG2 = namespace\log_call(range(1,2));
}
echo "Start\n";
var_export(MyClass::$DEBUG); echo "\n";
var_export(MyClass::$DEBUG2); echo "\n";
var_export(MyClass::$DEBUG); echo "\n";
MyClass::$DEBUG = "New value";
echo MyClass::$DEBUG . "\n";
?>
--EXPECT--
Start
log_call(true)
log_call(array (
0 => 1,
1 => 2,
))
true
array (
0 => 1,
1 => 2,
)
true
New value
40 changes: 40 additions & 0 deletions Zend/tests/call_in_const/recursion.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
Recursion in calls in class constants causes an error
--FILE--
<?php
function x_plus_1() {
echo "Computing X + 1\n";
return Recursion::X + 1;
}
class Recursion {
const X = x_plus_1();
const MISSING = MISSING_GLOBAL + 1;
}
try {
echo "Recursion::X=" . Recursion::X . "\n";
} catch (Error $e) {
printf("Caught %s: %s\n", get_class($e), $e->getMessage());
}
try {
echo "Recursion::X=" . Recursion::X . "\n";
} catch (Error $e) {
printf("Second call caught %s: %s\n", get_class($e), $e->getMessage());
}
try {
echo "Recursion::MISSING=" . Recursion::MISSING;
} catch (Error $e) {
printf("Caught %s: %s\n", get_class($e), $e->getMessage());
}
try {
echo "Recursion::MISSING=" . Recursion::MISSING;
} catch (Error $e) {
printf("Second call caught %s: %s\n", get_class($e), $e->getMessage());
}
?>
--EXPECT--
Computing X + 1
Caught Error: Unrecoverable error calling x_plus_1() in recursive constant definition
Computing X + 1
Second call caught Error: Unrecoverable error calling x_plus_1() in recursive constant definition
Caught Error: Undefined constant 'MISSING_GLOBAL'
Second call caught Error: Undefined constant 'MISSING_GLOBAL'
Loading