Skip to content

merge #5

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

Merged
merged 2 commits into from
Jan 31, 2019
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
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ PHP 8.0 UPGRADE NOTES
longer available. The error_get_last() function may be used instead.
. Removed the ability to define case-insensitive constants. The third
argument to define() may no longer be true.
. Access to undefined constants now always results in an Error exception.
Previously, unqualified constant accesses resulted in a warning and were
interpreted as strings.
. Removed ability to specify an autoloader using an __autoload() function.
spl_autoload_register() should be used instead.
. Removed create_function(). Anonymous functions may be used instead.
Expand Down
4 changes: 3 additions & 1 deletion Zend/tests/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ NULL

Warning: define() expects at least 2 parameters, 1 given in %s on line %d
NULL
bool(true)

Notice: Constant TRUE already defined in %s on line %d
bool(false)

Warning: define() expects parameter 3 to be bool, array given in %s on line %d
NULL
Expand Down
7 changes: 4 additions & 3 deletions Zend/tests/bug37811.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ string(3) "Foo"

Warning: Constants may only evaluate to scalar values, arrays or resources in %sbug37811.php on line %d

Warning: Use of undefined constant Baz - assumed 'Baz' (this will throw an Error in a future version of PHP) in %sbug37811.php on line %d
string(3) "Baz"
===DONE===
Fatal error: Uncaught Error: Undefined constant 'Baz' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
43 changes: 28 additions & 15 deletions Zend/tests/bug43344_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Bug #43344.1 (Wrong error message for undefined namespace constant)
--FILE--
<?php
namespace Foo;
use Error;

function f1($a=bar) {
return $a;
}
Expand All @@ -13,20 +15,31 @@ function f3($a=array(bar=>0)) {
reset($a);
return key($a);
}
echo bar."\n";
echo f1()."\n";
echo f2()."\n";
echo f3()."\n";
?>
--EXPECTF--
Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 13
bar

Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 3
bar

Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 6
bar
try {
echo bar."\n";
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
echo f1()."\n";
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
echo f2()."\n";
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
echo f3()."\n";
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 9
bar
?>
--EXPECT--
Undefined constant 'Foo\bar'
Undefined constant 'Foo\bar'
Undefined constant 'Foo\bar'
Undefined constant 'Foo\bar'
5 changes: 4 additions & 1 deletion Zend/tests/bug47572.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ $foo = new Foo();

?>
--EXPECTF--
Warning: Use of undefined constant FOO - assumed 'FOO' (this will throw an Error in a future version of PHP) in %s on line %d
Fatal error: Uncaught Error: Undefined constant 'FOO' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
5 changes: 4 additions & 1 deletion Zend/tests/bug69755.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ Bug #69755: segfault in ZEND_CONCAT_SPEC_TMPVAR_CONST_HANDLER
c . 10;
?>
--EXPECTF--
Warning: Use of undefined constant c - assumed 'c' (this will throw an Error in a future version of PHP) in %sbug69755.php on line 2
Fatal error: Uncaught Error: Undefined constant 'c' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
5 changes: 4 additions & 1 deletion Zend/tests/bug69788.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ Bug #69788: Malformed script causes Uncaught Error in php-cgi, valgrind SIGILL
--EXPECTF--
Notice: Array to string conversion in %s on line %d

Warning: Use of undefined constant t - assumed 't' (this will throw an Error in a future version of PHP) in %s on line %d
Fatal error: Uncaught Error: Undefined constant 't' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
5 changes: 2 additions & 3 deletions Zend/tests/bug72944.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
Bug #72944 (Null pointer deref in zval_delref_p).
--FILE--
<?php
define('e', 'e');
"a"== e & $A = $A? 0 : 0 ?:0;
echo "OK\n";
?>
--EXPECTF--
Warning: Use of undefined constant e - assumed 'e' (this will throw an Error in a future version of PHP) in %sbug72944.php on line 2

Notice: Undefined variable: A in %sbug72944.php on line 2
Notice: Undefined variable: A in %sbug72944.php on line 3
OK
22 changes: 0 additions & 22 deletions Zend/tests/bug73163.phpt

This file was deleted.

12 changes: 7 additions & 5 deletions Zend/tests/constants_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ Defining constants with non-scalar values
<?php

define('foo', new stdClass);
var_dump(foo);
try {
var_dump(foo);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

define('foo', fopen(__FILE__, 'r'));
var_dump(foo);

?>
--EXPECTF--
Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d

Warning: Use of undefined constant foo - assumed 'foo' (this will throw an Error in a future version of PHP) in %s on line %d
string(%d) "foo"
resource(%d) of type (stream)
Undefined constant 'foo'
resource(5) of type (stream)
7 changes: 3 additions & 4 deletions Zend/tests/constants_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
Persistent case insensitive and user defined constants
--FILE--
<?php
var_dump(ZEND_THREAD_safe);
var_dump(defined('ZEND_THREAD_safe'));
define("ZEND_THREAD_safe", 123);
var_dump(ZEND_THREAD_safe);
?>
--EXPECTF--
Warning: Use of undefined constant ZEND_THREAD_safe - assumed 'ZEND_THREAD_safe' (this will throw an Error in a future version of PHP) in %s on line %d
string(16) "ZEND_THREAD_safe"
--EXPECT--
bool(false)
int(123)
6 changes: 4 additions & 2 deletions Zend/tests/ns_041.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ ok
ok
ok

Warning: Use of undefined constant BAR - assumed 'BAR' (this will throw an Error in a future version of PHP) in %sns_041.php on line 9
BAR
Fatal error: Uncaught Error: Undefined constant 'test\ns1\BAR' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
38 changes: 20 additions & 18 deletions Zend/tests/ns_076.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
--FILE--
<?php
namespace foo;
use Error;

$a = array(unknown => unknown);

echo unknown;
echo "\n";
var_dump($a);
echo \unknown;
--EXPECTF--
Warning: Use of undefined constant unknown - assumed 'unknown' (this will throw an Error in a future version of PHP) in %sns_076.php on line %d
try {
$a = array(unknown => unknown);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

Warning: Use of undefined constant unknown - assumed 'unknown' (this will throw an Error in a future version of PHP) in %sns_076.php on line %d
try {
echo unknown;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

Warning: Use of undefined constant unknown - assumed 'unknown' (this will throw an Error in a future version of PHP) in %sns_076.php on line %d
unknown
array(1) {
["unknown"]=>
%s(7) "unknown"
try {
echo \unknown;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

Fatal error: Uncaught Error: Undefined constant 'unknown' in %sns_076.php:%d
Stack trace:
#0 {main}
thrown in %sns_076.php on line %d
?>
--EXPECT--
Undefined constant 'foo\unknown'
Undefined constant 'foo\unknown'
Undefined constant 'unknown'
2 changes: 1 addition & 1 deletion Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ ZEND_FUNCTION(defined)
Z_PARAM_STR(name)
ZEND_PARSE_PARAMETERS_END();

if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT | ZEND_GET_CONSTANT_NO_DEPRECATION_CHECK)) {
if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
Expand Down
60 changes: 13 additions & 47 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,6 @@ static int zend_add_const_name_literal(zend_string *name, zend_bool unqualified)
zend_str_tolower(ZSTR_VAL(tmp_name), ns_len);
zend_add_literal_string(&tmp_name);

/* lowercased namespace name & lowercased constant name */
tmp_name = zend_string_tolower(name);
zend_add_literal_string(&tmp_name);

if (!unqualified) {
return ret;
}
Expand All @@ -600,11 +596,6 @@ static int zend_add_const_name_literal(zend_string *name, zend_bool unqualified)
tmp_name = zend_string_init(after_ns, after_ns_len, 0);
zend_add_literal_string(&tmp_name);

/* lowercased unqualified constant name */
tmp_name = zend_string_alloc(after_ns_len, 0);
zend_str_tolower_copy(ZSTR_VAL(tmp_name), after_ns, after_ns_len);
zend_add_literal_string(&tmp_name);

return ret;
}
/* }}} */
Expand Down Expand Up @@ -1213,22 +1204,9 @@ ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char
}
/* }}} */

static zend_constant *zend_lookup_reserved_const(const char *name, size_t len) /* {{{ */
{
zend_constant *c = zend_hash_find_ptr_lc(EG(zend_constants), name, len);
if (c && !(ZEND_CONSTANT_FLAGS(c) & CONST_CS) && (ZEND_CONSTANT_FLAGS(c) & CONST_CT_SUBST)) {
return c;
}
return NULL;
}
/* }}} */

static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool is_fully_qualified) /* {{{ */
{
zend_constant *c;

/* Substitute case-sensitive (or lowercase) constants */
c = zend_hash_find_ptr(EG(zend_constants), name);
zend_constant *c = zend_hash_find_ptr(EG(zend_constants), name);
if (c && (
((ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT)
&& !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION)
Expand All @@ -1243,19 +1221,19 @@ static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool i
/* Substitute true, false and null (including unqualified usage in namespaces) */
const char *lookup_name = ZSTR_VAL(name);
size_t lookup_len = ZSTR_LEN(name);
zval *val;

if (!is_fully_qualified) {
zend_get_unqualified_name(name, &lookup_name, &lookup_len);
}

c = zend_lookup_reserved_const(lookup_name, lookup_len);
if (c) {
ZVAL_COPY_OR_DUP(zv, &c->value);
if ((val = zend_get_special_const(lookup_name, lookup_len))) {
ZVAL_COPY_VALUE(zv, val);
return 1;
}
}

return 0;
return 0;
}
}
/* }}} */

Expand Down Expand Up @@ -3249,13 +3227,6 @@ int zend_compile_func_defined(znode *result, zend_ast_list *args) /* {{{ */
LITERAL_STR(opline->op1, name);
opline->extended_value = zend_alloc_cache_slot();

/* Lowercase constant name in a separate literal */
{
zval c;
zend_string *lcname = zend_string_tolower(name);
ZVAL_NEW_STR(&c, lcname);
zend_add_literal(&c);
}
return SUCCESS;
}
/* }}} */
Expand Down Expand Up @@ -6538,7 +6509,7 @@ void zend_compile_const_decl(zend_ast *ast) /* {{{ */
value_node.op_type = IS_CONST;
zend_const_expr_to_zval(value_zv, value_ast);

if (zend_lookup_reserved_const(ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name))) {
if (zend_get_special_const(ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name))) {
zend_error_noreturn(E_COMPILE_ERROR,
"Cannot redeclare constant '%s'", ZSTR_VAL(unqualified_name));
}
Expand Down Expand Up @@ -7672,19 +7643,13 @@ void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */
opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, NULL);
opline->op2_type = IS_CONST;

if (is_fully_qualified) {
if (is_fully_qualified || !FC(current_namespace)) {
opline->op2.constant = zend_add_const_name_literal(
resolved_name, 0);
} else {
opline->op1.num = IS_CONSTANT_UNQUALIFIED;
if (FC(current_namespace)) {
opline->op1.num |= IS_CONSTANT_IN_NAMESPACE;
opline->op2.constant = zend_add_const_name_literal(
resolved_name, 1);
} else {
opline->op2.constant = zend_add_const_name_literal(
resolved_name, 0);
}
opline->op1.num = IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE;
opline->op2.constant = zend_add_const_name_literal(
resolved_name, 1);
}
opline->extended_value = zend_alloc_cache_slot();
}
Expand Down Expand Up @@ -8014,7 +7979,8 @@ void zend_compile_const_expr_const(zend_ast **ast_ptr) /* {{{ */
}

zend_ast_destroy(ast);
*ast_ptr = zend_ast_create_constant(resolved_name, !is_fully_qualified ? IS_CONSTANT_UNQUALIFIED : 0);
*ast_ptr = zend_ast_create_constant(resolved_name,
!is_fully_qualified && FC(current_namespace) ? IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE : 0);
}
/* }}} */

Expand Down
3 changes: 1 addition & 2 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,8 @@ void zend_assert_valid_class_name(const zend_string *const_name);

#define ZEND_DIM_IS 1

#define IS_CONSTANT_UNQUALIFIED 0x010
#define IS_CONSTANT_CLASS 0x080 /* __CLASS__ in trait */
#define IS_CONSTANT_IN_NAMESPACE 0x100
#define IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE 0x100

static zend_always_inline int zend_check_arg_send_type(const zend_function *zf, uint32_t arg_num, uint32_t mask)
{
Expand Down
Loading