How to fix PHP Fatal error: Cannot use result of built-in function due to an error in Tar.php line 639

Fatal error: Cannot use result of built-in function in write context
As of PHP 7.2, you might start encountering an error when installing a PEAR package via Shell or Command Prompt. The error it gives you is: PHP Fatal error: Cannot use result of built-in function in write context in …\php\pear\Archive\Tar.php on line 639
Fatal error: Cannot use result of built-in function in write context in …\pear\Archive\Tar.php on line 639

OK, so you might wonder what the heck happened? Actually, this issue has been since June 2017 or perhaps earlier, and even after a year, this issue might still be there. Now, I am using XAMPP as my Web Server on my PC. I have XAMPP v.7.2.4, and I tried installing a PEAR package for mail extension, and it still gave me this error. There was a mention about this on Github. It was said that this is a bug. The failure is a result of a new check in the Zend engine that returns the error “Cannot use result of built-in function in write context”.

Because of the PHP upgrade, some functions in the old PEAR scripts particularly in Tar.php stopped working. It was suggested that installing an updated version of Archive_Tar will solve the issue, so some may think that running PEAR update pear install Archive_Tar in the command prompt will do the trick. Well, wrong! How can you install when your installer is the problem? It’s common sense to fix the installer problem first.

To solve the issue, you may manually fix Tar.php. You can find it in path xampp\php\pear\Archive\ for XAMPP. The path could also be somewhat similar in other Web Server applications, with only the root directory is different.
tar.php
Next thing to do is to open the file Tar.php with a text editor designed for coding such as Sublime Text, Notepad++, or Atom, then go to the error — line 639…
line 639
The issue is:
$v_att_list = & func_get_args();

This special character “&” is causing the problem. Why? Because & means that func_get_args() should be called by reference. Remove that so that the code will look like:

$v_att_list = func_get_args();

The above fix solves the problem, but it is best to update the Archive Tar PEAR package afterwards by typing:

pear install Archive_Tar

…in the shell. This will ensure that you are running the latest version.

Follow me at:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.