Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into native-tls
Browse files Browse the repository at this point in the history
* origin/master: (31 commits)
  Fixed C++ incompatibility
  update the certificate used for the test, as it expired recently
  Fixed immutable arrays support
  Fix counting of "R:" references in serialize()
  Remove dead code
  Test use($this) being an error
  Move list() condition into assign_znode
  typo
  NEWS
  Fix bug #68074 Allow to use system cipher list instead of hardcoded value
  Avoid double checks
  the order of the blocks should be Core, then exts in alphabetical order
  add missing NEWS entry for the phpdbg compilation fix
  add NEWS entry for #68088
  Make QM_ASSIGN, JMP_SET and CAST return IS_TMP_VAR.
  Removed useless helper
  Drop unused result argument
  Fix ct binding for cuf/cufa functions
  Fix detection of write to built-in function for references
  Test use of string names with \ prefix
  ...
  • Loading branch information
weltling committed Sep 24, 2014
2 parents 70077d8 + 6a09bdf commit a2dd606
Show file tree
Hide file tree
Showing 46 changed files with 1,111 additions and 1,177 deletions.
10 changes: 10 additions & 0 deletions Zend/tests/builtin_in_write_context_error1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot use built-in functions in write context (assignment)
--FILE--
<?php

strlen("foo")[0] = 1;

?>
--EXPECTF--
Fatal error: Cannot use result of built-in function in write context in %s on line %d
10 changes: 10 additions & 0 deletions Zend/tests/builtin_in_write_context_error2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot use built-in functions in write context (reference)
--FILE--
<?php

$ref =& strlen("foo");

?>
--EXPECTF--
Fatal error: Cannot use result of built-in function in write context in %s on line %d
10 changes: 10 additions & 0 deletions Zend/tests/class_name_as_scalar_error_007.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot access self::class when no class scope is active
--FILE--
<?php

var_dump(self::class);

?>
--EXPECTF--
Fatal error: Cannot access self::class when no class scope is active in %s on line %d
76 changes: 71 additions & 5 deletions Zend/tests/constant_expressions_dynamic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,76 @@
Dynamic Constant Expressions
--FILE--
<?php
const FOO = 1;
const BAR = FOO | 2;

echo BAR;
const C_0 = 0;
const C_1 = 1;
const C_foo = "foo";
const C_arr = [0 => 0, "foo" => "foo"];

const T_1 = C_1 | 2;
const T_2 = C_1 . "foo";
const T_3 = C_1 > 1;
const T_4 = C_1 >= 1;
const T_5 = -C_1;
const T_6 = +C_1;
const T_7 = +C_foo;
const T_8 = !C_1;
const T_9 = C_0 || 0;
const T_10 = C_1 || 0;
const T_11 = C_0 && 1;
const T_12 = C_1 && 1;
const T_13 = C_0 ? "foo" : "bar";
const T_14 = C_1 ? "foo" : "bar";
const T_15 = C_0 ?: "bar";
const T_16 = C_1 ?: "bar";
const T_17 = C_arr[0];
const T_18 = C_arr["foo"];
const T_19 = [
C_0,
"foo" => "foo",
42 => 42,
3.14 => 3.14,
null => null,
false => false,
true => true,
];

var_dump(
T_1, T_2, T_3, T_4, T_5, T_6, T_7, T_8, T_9, T_10,
T_11, T_12, T_13, T_14, T_15, T_16, T_17, T_18, T_19
);

?>
--EXPECTF--
3
--EXPECT--
int(3)
string(4) "1foo"
bool(false)
bool(true)
int(-1)
int(1)
int(0)
bool(false)
bool(false)
bool(true)
bool(false)
bool(true)
string(3) "bar"
string(3) "foo"
string(3) "bar"
int(1)
int(0)
string(3) "foo"
array(6) {
[0]=>
bool(false)
["foo"]=>
string(3) "foo"
[42]=>
int(42)
[3]=>
float(3.14)
[""]=>
NULL
[1]=>
bool(true)
}
11 changes: 11 additions & 0 deletions Zend/tests/constant_expressions_dynamic_class_name_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Dynamic class names can't be used in compile-time constant refs
--FILE--
<?php

$foo = 'test';
const C = $foo::BAR;

?>
--EXPECTF--
Fatal error: Dynamic class names are not allowed in compile-time class constant references in %s on line %d
11 changes: 11 additions & 0 deletions Zend/tests/constant_expressions_invalid_offset_type_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Can't use arrays as key for constant array
--FILE--
<?php

const C1 = 1; // force dynamic evaluation
const C2 = [C1, [] => 1];

?>
--EXPECTF--
Fatal error: Illegal offset type in %s on line %d
10 changes: 10 additions & 0 deletions Zend/tests/constant_expressions_static_class_name_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot use static::FOO in constant expressions
--FILE--
<?php

const C = static::FOO;

?>
--EXPECTF--
Fatal error: "static::" is not allowed in compile-time constants in %s on line %d
12 changes: 12 additions & 0 deletions Zend/tests/duplicate_label_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Duplicate labels are not allowed
--FILE--
<?php

foo:
foo:
goto foo;

?>
--EXPECTF--
Fatal error: Label 'foo' already defined in %s on line %d
26 changes: 26 additions & 0 deletions Zend/tests/magic_const_in_global_scope.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Test use of magic constants in the global scope
--FILE--
<?php

var_dump(
__LINE__,
__FILE__,
__DIR__,
__FUNCTION__,
__METHOD__,
__CLASS__,
__TRAIT__,
__NAMESPACE__
);

?>
--EXPECTF--
int(4)
string(%d) "%s"
string(%d) "%s"
string(0) ""
string(0) ""
string(0) ""
string(0) ""
string(0) ""
10 changes: 10 additions & 0 deletions Zend/tests/special_name_error1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot use special class name as namespace
--FILE--
<?php

namespace self;

?>
--EXPECTF--
Fatal error: Cannot use 'self' as namespace name in %s on line %d
10 changes: 10 additions & 0 deletions Zend/tests/special_name_error2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot use special class name as alias
--FILE--
<?php

use Foo\Bar as self;

?>
--EXPECTF--
Fatal error: Cannot use Foo\Bar as self because 'self' is a special class name in %s on line %d
10 changes: 10 additions & 0 deletions Zend/tests/special_name_error3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Cannot use special class name as trait name
--FILE--
<?php

trait self {}

?>
--EXPECTF--
Fatal error: Cannot use 'self' as class name as it is reserved in %s on line %d
14 changes: 14 additions & 0 deletions Zend/tests/this_as_lexical_var_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Cannot use $this as lexical variable
--FILE--
<?php

class Foo {
public function fn() {
return function() use ($this) {};
}
}

?>
--EXPECTF--
Fatal error: Cannot use $this as lexical variable in %s on line %d
2 changes: 2 additions & 0 deletions Zend/tests/varSyntax/indirectFcall.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $obj = new Test;
['Test', 'id']()()('var_dump')(11);
'id'()('id')('var_dump')(12);
('i' . 'd')()('var_dump')(13);
'\id'('var_dump')(14);

?>
--EXPECT--
Expand All @@ -51,3 +52,4 @@ int(10)
int(11)
int(12)
int(13)
int(14)
2 changes: 2 additions & 0 deletions Zend/tests/varSyntax/staticMember.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var_dump($A_str::$b);
var_dump($A_obj::$b);
var_dump(('A' . '')::$b);
var_dump('A'::$b);
var_dump('\A'::$b);
var_dump('A'[0]::$b);
var_dump(A::$$b_str);
var_dump(A::$$c_str[1]);
Expand All @@ -33,5 +34,6 @@ int(0)
int(0)
int(0)
int(0)
int(0)
int(1)
int(0)
75 changes: 3 additions & 72 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,79 +216,10 @@ ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy TSRMLS_DC) /*
{
if (Z_TYPE_P(expr) == IS_STRING) {
return 0;
} else {
ZVAL_STR(expr_copy, _zval_get_string_func(expr TSRMLS_CC));
return 1;
}

again:
switch (Z_TYPE_P(expr)) {
case IS_NULL:
case IS_FALSE:
ZVAL_EMPTY_STRING(expr_copy);
break;
case IS_TRUE:
if (CG(one_char_string)['1']) {
ZVAL_INTERNED_STR(expr_copy, CG(one_char_string)['1']);
} else {
ZVAL_NEW_STR(expr_copy, zend_string_init("1", 1, 0));
}
break;
case IS_RESOURCE: {
char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
int len;

len = snprintf(buf, sizeof(buf), "Resource id #" ZEND_LONG_FMT, Z_RES_HANDLE_P(expr));
ZVAL_NEW_STR(expr_copy, zend_string_init(buf, len, 0));
}
break;
case IS_ARRAY:
zend_error(E_NOTICE, "Array to string conversion");
// TODO: use interned string ???
ZVAL_NEW_STR(expr_copy, zend_string_init("Array", sizeof("Array") - 1, 0));
break;
case IS_OBJECT:
if (Z_OBJ_HANDLER_P(expr, cast_object)) {
Z_ADDREF_P(expr);
if (Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
zval_ptr_dtor(expr);
break;
}
zval_ptr_dtor(expr);
}
if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) {
zval rv;
zval *z = Z_OBJ_HANDLER_P(expr, get)(expr, &rv TSRMLS_CC);

Z_ADDREF_P(z);
if (Z_TYPE_P(z) != IS_OBJECT) {
if (zend_make_printable_zval(z, expr_copy TSRMLS_CC)) {
zval_ptr_dtor(z);
} else {
ZVAL_ZVAL(expr_copy, z, 0, 1);
}
return 1;
}
zval_ptr_dtor(z);
}
zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name->val);
ZVAL_EMPTY_STRING(expr_copy);
break;
case IS_DOUBLE:
ZVAL_DUP(expr_copy, expr);
zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
break;
case IS_REFERENCE:
expr = Z_REFVAL_P(expr);
if (Z_TYPE_P(expr) == IS_STRING) {
ZVAL_STR_COPY(expr_copy, Z_STR_P(expr));
return 1;
}
goto again;
break;
default:
ZVAL_DUP(expr_copy, expr);
convert_to_string(expr_copy);
break;
}
return 1;
}
/* }}} */

Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ static zend_always_inline zval *zend_ast_get_zval(zend_ast *ast) {
return &((zend_ast_zval *) ast)->val;
}
static zend_always_inline zend_string *zend_ast_get_str(zend_ast *ast) {
return Z_STR_P(zend_ast_get_zval(ast));
zval *zv = zend_ast_get_zval(ast);
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
return Z_STR_P(zv);
}

static zend_always_inline uint32_t zend_ast_get_num_children(zend_ast *ast) {
Expand Down
19 changes: 2 additions & 17 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1773,23 +1773,8 @@ ZEND_FUNCTION(get_defined_functions)

zend_hash_apply_with_arguments(EG(function_table) TSRMLS_CC, copy_function_name, 2, &internal, &user);

ret = zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);

if (!ret) {
zval_ptr_dtor(&internal);
zval_ptr_dtor(&user);
zval_dtor(return_value);
zend_error(E_WARNING, "Cannot add internal functions to return value from get_defined_functions()");
RETURN_FALSE;
}

ret = zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
if (!ret) {
zval_ptr_dtor(&user);
zval_dtor(return_value);
zend_error(E_WARNING, "Cannot add user functions to return value from get_defined_functions()");
RETURN_FALSE;
}
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
}
/* }}} */

Expand Down
Loading

0 comments on commit a2dd606

Please sign in to comment.