Skip to content

Commit 4d3e4d3

Browse files
committed
Remove assignment of new by reference
1 parent 23b683c commit 4d3e4d3

File tree

14 files changed

+19
-160
lines changed

14 files changed

+19
-160
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
. Removed scoped calls of non-static methods from an incompatible $this
3838
context. (Nikita)
3939
. Removed support for #-style comments in ini files. (Nikita)
40+
. Removed support for assigning the result of new by reference. (Nikita)
4041
. Invalid octal literals in source code now produce compile errors, fixes PHPSadness #31. (Andrea)
4142

4243
- Date:

UPGRADING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ PHP X.Y UPGRADE NOTES
5454
. zend_function.common.num_args don't include the variadic argument anymore.
5555
. ob_start() no longer issues an E_ERROR, but instead an E_RECOVERABLE_ERROR in case an
5656
output buffer is created in an output buffer handler.
57+
. Removed support for assigning the result of new by reference.
5758
. Removed support for scoped calls to non-static methods from an incompatible
5859
$this context. See details in https://wiki.php.net/rfc/incompat_ctx.
5960
. Removed support for #-style comments in ini files. Use ;-style comments

Zend/tests/bug45178.phpt

Lines changed: 0 additions & 29 deletions
This file was deleted.

Zend/zend_compile.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,6 @@ void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
23412341

23422342
if (zend_is_call(source_ast)) {
23432343
opline->extended_value = ZEND_RETURNS_FUNCTION;
2344-
} else if (source_ast->kind == ZEND_AST_NEW) {
2345-
zend_error(E_DEPRECATED, "Assigning the return value of new by reference is deprecated");
2346-
opline->extended_value = ZEND_RETURNS_NEW;
23472344
}
23482345
}
23492346
/* }}} */
@@ -6361,11 +6358,8 @@ void zend_compile_var(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
63616358
if (type == BP_VAR_W || type == BP_VAR_REF
63626359
|| type == BP_VAR_RW || type == BP_VAR_UNSET
63636360
) {
6364-
/* For BC reasons =& new Foo is allowed */
6365-
if (type != BP_VAR_REF || ast->kind != ZEND_AST_NEW) {
6366-
zend_error_noreturn(E_COMPILE_ERROR,
6367-
"Cannot use temporary expression in write context");
6368-
}
6361+
zend_error_noreturn(E_COMPILE_ERROR,
6362+
"Cannot use temporary expression in write context");
63696363
}
63706364

63716365
zend_compile_expr(result, ast);

Zend/zend_compile.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,7 @@ static zend_always_inline int zend_check_arg_send_type(const zend_function *zf,
858858

859859

860860
#define ZEND_RETURNS_FUNCTION 1<<0
861-
#define ZEND_RETURNS_NEW 1<<1
862-
#define ZEND_RETURNS_VALUE 1<<2
861+
#define ZEND_RETURNS_VALUE 1<<1
863862

864863
#define ZEND_FAST_RET_TO_CATCH 1
865864
#define ZEND_FAST_RET_TO_FINALLY 2

Zend/zend_language_parser.y

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,6 @@ expr_without_variable:
769769
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
770770
| variable '=' '&' variable
771771
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
772-
| variable '=' '&' new_expr
773-
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
774772
| T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2); }
775773
| variable T_PLUS_EQUAL expr
776774
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_ADD, $1, $3); }

Zend/zend_vm_def.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,10 +1818,6 @@ ZEND_VM_HANDLER(39, ZEND_ASSIGN_REF, VAR|CV, VAR|CV)
18181818
HANDLE_EXCEPTION();
18191819
}
18201820
ZEND_VM_DISPATCH_TO_HANDLER(ZEND_ASSIGN);
1821-
} else if (OP2_TYPE == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
1822-
if (!OP2_FREE) {
1823-
PZVAL_LOCK(value_ptr);
1824-
}
18251821
}
18261822

18271823
variable_ptr = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
@@ -1840,12 +1836,6 @@ ZEND_VM_HANDLER(39, ZEND_ASSIGN_REF, VAR|CV, VAR|CV)
18401836
zend_assign_to_variable_reference(variable_ptr, value_ptr);
18411837
}
18421838

1843-
if (OP2_TYPE == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
1844-
if (!OP2_FREE) {
1845-
Z_DELREF_P(variable_ptr);
1846-
}
1847-
}
1848-
18491839
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
18501840
ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr);
18511841
}

Zend/zend_vm_execute.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14200,10 +14200,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDL
1420014200
HANDLE_EXCEPTION();
1420114201
}
1420214202
return ZEND_ASSIGN_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
14203-
} else if (IS_VAR == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
14204-
if (!(free_op2 != NULL)) {
14205-
PZVAL_LOCK(value_ptr);
14206-
}
1420714203
}
1420814204

1420914205
variable_ptr = _get_zval_ptr_ptr_var(opline->op1.var, execute_data, &free_op1);
@@ -14222,12 +14218,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDL
1422214218
zend_assign_to_variable_reference(variable_ptr, value_ptr);
1422314219
}
1422414220

14225-
if (IS_VAR == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
14226-
if (!(free_op2 != NULL)) {
14227-
Z_DELREF_P(variable_ptr);
14228-
}
14229-
}
14230-
1423114221
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
1423214222
ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr);
1423314223
}
@@ -16210,10 +16200,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLE
1621016200
HANDLE_EXCEPTION();
1621116201
}
1621216202
return ZEND_ASSIGN_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
16213-
} else if (IS_CV == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
16214-
if (!0) {
16215-
PZVAL_LOCK(value_ptr);
16216-
}
1621716203
}
1621816204

1621916205
variable_ptr = _get_zval_ptr_ptr_var(opline->op1.var, execute_data, &free_op1);
@@ -16232,12 +16218,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLE
1623216218
zend_assign_to_variable_reference(variable_ptr, value_ptr);
1623316219
}
1623416220

16235-
if (IS_CV == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
16236-
if (!0) {
16237-
Z_DELREF_P(variable_ptr);
16238-
}
16239-
}
16240-
1624116221
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
1624216222
ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr);
1624316223
}
@@ -27366,10 +27346,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_VAR_HANDLER(ZEND_OPCODE_HANDLE
2736627346
HANDLE_EXCEPTION();
2736727347
}
2736827348
return ZEND_ASSIGN_SPEC_CV_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
27369-
} else if (IS_VAR == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
27370-
if (!(free_op2 != NULL)) {
27371-
PZVAL_LOCK(value_ptr);
27372-
}
2737327349
}
2737427350

2737527351
variable_ptr = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->op1.var);
@@ -27388,12 +27364,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_VAR_HANDLER(ZEND_OPCODE_HANDLE
2738827364
zend_assign_to_variable_reference(variable_ptr, value_ptr);
2738927365
}
2739027366

27391-
if (IS_VAR == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
27392-
if (!(free_op2 != NULL)) {
27393-
Z_DELREF_P(variable_ptr);
27394-
}
27395-
}
27396-
2739727367
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2739827368
ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr);
2739927369
}
@@ -30132,10 +30102,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_CV_HANDLER(ZEND_OPCODE_HANDLER
3013230102
HANDLE_EXCEPTION();
3013330103
}
3013430104
return ZEND_ASSIGN_SPEC_CV_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
30135-
} else if (IS_CV == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
30136-
if (!0) {
30137-
PZVAL_LOCK(value_ptr);
30138-
}
3013930105
}
3014030106

3014130107
variable_ptr = _get_zval_ptr_cv_undef_BP_VAR_W(execute_data, opline->op1.var);
@@ -30154,12 +30120,6 @@ static int ZEND_FASTCALL ZEND_ASSIGN_REF_SPEC_CV_CV_HANDLER(ZEND_OPCODE_HANDLER
3015430120
zend_assign_to_variable_reference(variable_ptr, value_ptr);
3015530121
}
3015630122

30157-
if (IS_CV == IS_VAR && opline->extended_value == ZEND_RETURNS_NEW) {
30158-
if (!0) {
30159-
Z_DELREF_P(variable_ptr);
30160-
}
30161-
}
30162-
3016330123
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
3016430124
ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr);
3016530125
}

ext/standard/tests/serialize/bug31402.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Bug #31402 (unserialize() generates references when it should not)
33
--INI--
4-
error_reporting=E_ALL&~E_STRICT&~E_DEPRECATED
4+
error_reporting=E_ALL
55
--FILE--
66
<?php
77

@@ -19,7 +19,8 @@ class TestY {
1919

2020
function __construct() {
2121
$this->A[1] = new TestX(1);
22-
$this->A[2] = & new TestX(2);
22+
$obj = new TestX(2);
23+
$this->A[2] = & $obj;
2324
$this->A[3] = & $this->A[2];
2425
$this->B = $this->A[1];
2526
}

tests/classes/new_001.phpt

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)