Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

centos - Updated server from php 5.6 to 7.3, getting PEAR error

I recently updated my server php version from 5.6 to 7.3. When I attempt to load a page I'm seeing the following parse error:

Parse error: syntax error, unexpected 'new' (T_NEW) in /usr/share/pear/MDB2/Driver/mysqli.php on line 940

The file above is automatically installed via pear, here is the section prompting the error:

938 
939         $class_name = 'MDB2_Statement_'.$this->phptype;
940         $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $        offset);
941         $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
942         return $obj;
943     }
944 

I've updated all pear packages using pear upgrade-all, restarted httpd and continue to get the same error above.

question from:https://stackoverflow.com/questions/65848943/updated-server-from-php-5-6-to-7-3-getting-pear-error

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

1 Reply

0 votes
by (71.8m points)

Your problem is with the =&, which should be simply =, in $obj =& new .... Objects can't, shouldn't, and don't need to, be created by reference. Such an expression was deprecated in PHP 5 and made invalid in PHP 7 (see eval response on different PHP versions).

It's a mystery to me why the PEAR package should have this, it must be a vestige from forever ago. It makes no more sense than $x =& []; (which would also result in an error). When an object is assigned to a variable, the variable becomes a pointer to the object. Therefore:

$a = new stdClass();
var_dump($a);
// object(stdClass)#1 (0) {}

$b = $a;
var_dump($b);
// object(stdClass)#1 (0) {}

var_dump($a === $b);
// bool(true)

That is: even without assigning $b =& $a, both variables point to the same object by default (ie. to object(stdClass)#1). Clean those up and drop a note to the PEAR package maintainers. FYI, the MDB2_Driver_mysqli package was last updated on 2012-10-23, so fetching the latest updates won't help much. Look for an up-to-date replacement. (Core PHP has had mysqli built in since PHP 5 and also has PDO if you need code portability between different RDBMs).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...