File tree Expand file tree Collapse file tree
tests/partial_application Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ --TEST--
2+ Partial function application on methods named assert() must invoke the method, while real global assert(?) keeps working
3+ --INI--
4+ zend.assertions=1
5+ assert.exception=1
6+ --FILE--
7+ <?php
8+
9+ class Validator {
10+ public function assert (bool $ cond , string $ label = 'default ' ): string {
11+ return "INSTANCE: $ label: " . ($ cond ? 'true ' : 'false ' );
12+ }
13+
14+ public static function assertStatic (bool $ cond ): string {
15+ return "CTRL: " . ($ cond ? 'true ' : 'false ' );
16+ }
17+ }
18+
19+ class StaticValidator {
20+ public static function assert (bool $ cond , string $ label = 'static ' ): string {
21+ return "STATIC: $ label: " . ($ cond ? 'true ' : 'false ' );
22+ }
23+ }
24+
25+ $ v = new Validator ();
26+ $ ctrl = $ v ->assertStatic (?);
27+ var_dump ($ ctrl (false ));
28+
29+ $ p1 = $ v ->assert (?, 'inst ' );
30+ var_dump ($ p1 (false ));
31+
32+ $ p2 = StaticValidator ::assert (?, 'cls ' );
33+ var_dump ($ p2 (false ));
34+
35+ $ p3 = $ v ->assert (...);
36+ var_dump ($ p3 (false , 'fcc ' ));
37+
38+ // Positive control: real global \assert(?) must still invoke global assert()
39+ $ realAssert = \assert (?, 'real-assert-msg ' );
40+ var_dump ($ realAssert (true ));
41+ try {
42+ $ realAssert (false );
43+ echo "UNEXPECTED_PASS \n" ;
44+ } catch (AssertionError $ e ) {
45+ echo "REAL_ASSERT_ERR: " . $ e ->getMessage () . "\n" ;
46+ }
47+
48+ ?>
49+ --EXPECT--
50+ string(10) "CTRL:false"
51+ string(19) "INSTANCE:inst:false"
52+ string(16) "STATIC:cls:false"
53+ string(18) "INSTANCE:fcc:false"
54+ bool(true)
55+ REAL_ASSERT_ERR:real-assert-msg
Original file line number Diff line number Diff line change @@ -522,8 +522,10 @@ static zend_ast *zp_compile_forwarding_call(
522522 bool forward_superfluous_args ,
523523 zend_ast * stmts_ast , uint32_t const_args )
524524{
525- bool is_assert = zend_string_equals (function -> common .function_name ,
526- ZSTR_KNOWN (ZEND_STR_ASSERT ));
525+ bool is_assert = function -> type == ZEND_INTERNAL_FUNCTION
526+ && !function -> common .scope
527+ && zend_string_equals (function -> common .function_name ,
528+ ZSTR_KNOWN (ZEND_STR_ASSERT ));
527529
528530 zend_ast * args_ast = zend_ast_create_list (0 , ZEND_AST_ARG_LIST );
529531 zend_ast * call_ast = NULL ;
You can’t perform that action at this time.
0 commit comments