Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ PHP NEWS
. Fixed bug GH-25379 (array_map() foreach optimization changes callback
semantics). (prateekbhujel)
. Fix OSS-Fuzz #588264417. (ndossche)
. Fixed partial application treating methods named assert() as the global
assert(). (hohphu8)

- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
Expand Down
55 changes: 55 additions & 0 deletions Zend/tests/partial_application/method_named_assert.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
Partial function application on methods named assert() must invoke the method, while real global assert(?) keeps working
--INI--
zend.assertions=1
assert.exception=1
--FILE--
<?php

class Validator {
public function assert(bool $cond, string $label = 'default'): string {
return "INSTANCE:$label:" . ($cond ? 'true' : 'false');
}

public static function assertStatic(bool $cond): string {
return "CTRL:" . ($cond ? 'true' : 'false');
}
}

class StaticValidator {
public static function assert(bool $cond, string $label = 'static'): string {
return "STATIC:$label:" . ($cond ? 'true' : 'false');
}
}

$v = new Validator();
$ctrl = $v->assertStatic(?);
var_dump($ctrl(false));

$p1 = $v->assert(?, 'inst');
var_dump($p1(false));

$p2 = StaticValidator::assert(?, 'cls');
var_dump($p2(false));

$p3 = $v->assert(...);
var_dump($p3(false, 'fcc'));

// Positive control: real global \assert(?) must still invoke global assert()
$realAssert = \assert(?, 'real-assert-msg');
var_dump($realAssert(true));
try {
$realAssert(false);
echo "UNEXPECTED_PASS\n";
} catch (AssertionError $e) {
echo "REAL_ASSERT_ERR:" . $e->getMessage() . "\n";
}

?>
--EXPECT--
string(10) "CTRL:false"
string(19) "INSTANCE:inst:false"
string(16) "STATIC:cls:false"
string(18) "INSTANCE:fcc:false"
bool(true)
REAL_ASSERT_ERR:real-assert-msg
6 changes: 4 additions & 2 deletions Zend/zend_partial.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,10 @@ static zend_ast *zp_compile_forwarding_call(
bool forward_superfluous_args,
zend_ast *stmts_ast, uint32_t const_args)
{
bool is_assert = zend_string_equals(function->common.function_name,
ZSTR_KNOWN(ZEND_STR_ASSERT));
bool is_assert = function->type == ZEND_INTERNAL_FUNCTION
&& !function->common.scope
&& zend_string_equals(function->common.function_name,
ZSTR_KNOWN(ZEND_STR_ASSERT));

zend_ast *args_ast = zend_ast_create_list(0, ZEND_AST_ARG_LIST);
zend_ast *call_ast = NULL;
Expand Down