Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

syntax error - Is pass by reference supported in php 7?

Recently we migrated PHP 5.6 to PHP 7

and now following code throws $this->a =& new test($this->f);

Parse error: syntax error, unexpected 'new' (T_NEW) 

any ideas? what are the alternation that I could use for it?

question from:https://stackoverflow.com/questions/65925534/php-parse-error-syntax-error-unexpected-new-t-new-and-its-always-because

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As per the PHP7 incompatible changes: http://php.net/manual/en/migration70.incompatible.php

New objects cannot be assigned by reference

The result of the new statement can no longer be assigned to a variable by reference: <?php class C {} $c =& new C; ?>

Output of the above example in PHP 5:

Deprecated: Assigning the return value of new by reference is deprecated in /tmp/test.php on line 3

Output of the above example in PHP 7:

Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php on line 3

There is no alternative. You were using deprecated behavior, and now it's no longer valid PHP. Simply don't assign by reference.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...