mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
Fixed assert() in namesapaces
This commit is contained in:
parent
5eba069c28
commit
96de5ffc8d
24
Zend/tests/assert/expect_016.phpt
Normal file
24
Zend/tests/assert/expect_016.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
test enable/disable assertions at runtime (assertions not completely disabled)
|
||||
--INI--
|
||||
zend.assertions=0
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
ini_set("zend.assertions", 0);
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", 1);
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", -1);
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: assert(): assert(false) failed in %sexpect_016.php on line 6
|
||||
NULL
|
||||
bool(true)
|
||||
|
||||
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_016.php on line 8
|
19
Zend/tests/assert/expect_017.phpt
Normal file
19
Zend/tests/assert/expect_017.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
test enable/disable assertions at runtime (assertions completely disabled)
|
||||
--INI--
|
||||
zend.assertions=-1
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", 0);
|
||||
ini_set("zend.assertions", 1);
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 4
|
||||
|
||||
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 5
|
33
Zend/tests/assert/expect_018.phpt
Normal file
33
Zend/tests/assert/expect_018.phpt
Normal file
@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
test assertions in namespace
|
||||
--INI--
|
||||
zend.assertions=1
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Foo;
|
||||
|
||||
ini_set("zend.assertions", 0);
|
||||
var_dump(\assert(false));
|
||||
var_dump(\assert(true));
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
ini_set("zend.assertions", 1);
|
||||
var_dump(\assert(false));
|
||||
var_dump(\assert(true));
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: assert(): assert(false) failed in %sexpect_018.php on line 10
|
||||
NULL
|
||||
bool(true)
|
||||
|
||||
Warning: assert(): assert(false) failed in %sexpect_018.php on line 12
|
||||
NULL
|
||||
bool(true)
|
19
Zend/tests/assert/expect_019.phpt
Normal file
19
Zend/tests/assert/expect_019.phpt
Normal file
@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
test assertions in namespace (assertions completely disabled)
|
||||
--INI--
|
||||
zend.assertions=-1
|
||||
assert.exception=0
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Foo;
|
||||
|
||||
var_dump(\assert(false));
|
||||
var_dump(\assert(true));
|
||||
var_dump(assert(false));
|
||||
var_dump(assert(true));
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
@ -116,6 +116,7 @@ static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
|
||||
|
||||
if (stage != ZEND_INI_STAGE_STARTUP &&
|
||||
stage != ZEND_INI_STAGE_SHUTDOWN &&
|
||||
*p != val &&
|
||||
(*p < 0 || val < 0)) {
|
||||
zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
|
||||
return FAILURE;
|
||||
|
@ -2817,19 +2817,26 @@ int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcnam
|
||||
|
||||
|
||||
|
||||
static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *lcname, zend_function *fbc) /* {{{ */
|
||||
static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc) /* {{{ */
|
||||
{
|
||||
if (EG(assertions) >= 0) {
|
||||
znode name_node;
|
||||
znode name_node;
|
||||
zend_op *opline;
|
||||
uint32_t check_op_number = get_next_op_number(CG(active_op_array));
|
||||
|
||||
zend_emit_op(NULL, ZEND_ASSERT_CHECK, NULL, NULL);
|
||||
|
||||
name_node.op_type = IS_CONST;
|
||||
ZVAL_STR_COPY(&name_node.u.constant, lcname);
|
||||
if (fbc) {
|
||||
name_node.op_type = IS_CONST;
|
||||
ZVAL_STR_COPY(&name_node.u.constant, name);
|
||||
|
||||
opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
|
||||
opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
|
||||
} else {
|
||||
opline = zend_emit_op(NULL, ZEND_INIT_NS_FCALL_BY_NAME, NULL, NULL);
|
||||
opline->op2_type = IS_CONST;
|
||||
opline->op2.constant = zend_add_ns_func_name_literal(
|
||||
CG(active_op_array), name);
|
||||
}
|
||||
zend_alloc_cache_slot(opline->op2.constant);
|
||||
|
||||
if (args->children == 1 &&
|
||||
@ -2844,6 +2851,12 @@ static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *
|
||||
zend_compile_call_common(result, (zend_ast*)args, fbc);
|
||||
|
||||
CG(active_op_array)->opcodes[check_op_number].op2.opline_num = get_next_op_number(CG(active_op_array));
|
||||
} else {
|
||||
if (!fbc) {
|
||||
zend_string_release(name);
|
||||
}
|
||||
result->op_type = IS_CONST;
|
||||
ZVAL_TRUE(&result->u.constant);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
@ -2906,7 +2919,11 @@ void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
|
||||
{
|
||||
zend_bool runtime_resolution = zend_compile_function_name(&name_node, name_ast);
|
||||
if (runtime_resolution) {
|
||||
zend_compile_ns_call(result, &name_node, args_ast);
|
||||
if (zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")) {
|
||||
zend_compile_assert(result, args_ast, Z_STR(name_node.u.constant), NULL);
|
||||
} else {
|
||||
zend_compile_ns_call(result, &name_node, args_ast);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user