PHP troubleshooting

A golden rule

First check whether everything is spelled correctly, that may save you much unnecessary time.

PHP Parse error: syntax error, unexpected end of file

PHP Parse error:  syntax error, unexpected end of file in /xxx/xxx/xx.php on line xxx

That’s probably because you miss a right curly brace } somewhere in the code. You can comment some code and limit down the range where error occurs.

Fatal error: Call to a member function xxx on null in xxx

Notice: Undefined variable: parser in /xxx/xxx.php on line xx
PHP Fatal error:  Uncaught Error: Call to a member function parse() on null in /xxx/xxx.php:xx
  1. Check whether the log also says PHP Notice: Undefined variable: xxx in xxx. If it is, there are 2 cases:
    • The variable is spelled incorrectly.
    • The variable is not defined.
  2. Check whether the object variable the function belongs to is initiated correctly.

Fatal error: Class ‘xxx’ not found

PHP Fatal error:  Uncaught Error: Class 'modmdMyClass' not found in /xxx/xxx.php:xx
  1. Check whether you spell the class and the include statement correctly.
  2. Make sure include the relevant file with include or require.
  3. Make sure include the relevant file in a correct order. Take a example, a.php uses something of b.php, b.php uses something of c.php and b.php does not include c.php. In a.php, include c.php first then include b.php .

Fixing WordPress update error: The checksum of the file (xxx) does not match the expected checksum value ()

If you are getting the following error when you trying to update WordPress. Then this article may helps you.

Downloading update from https://downloads.wordpress.org/release/wordpress-xxx-partial-x.zip…

Download failed.: The checksum of the file (xxx) does not match the expected checksum value ().

Installation Failed

Check disk space and permissions

The most probable two situations you need to check are:

  • Check disk space. You are probably running out of the disk space. If you are on a Linux server, run df -h to check the available space.
  • Check permissions. When you are updating WordPress on the dashboard by clicking Update now button, the user is that one that running the Web server. Make sure that user have write permission to the WordPress core files. See the tutorial on Changing File Permissions for more information,

Restart your Web server

If neither of the situations mentioned above is your problem, and you’ve updated WordPress successfully the last time, and nothing seemed to have been changed afterwards, just try to restart your web server. Then update again.

Update via WP-CLI

If no luck once again, maybe you can attempt to update WordPress through WP-CLI (WordPress Command Line Interface). Getting started to use WP-CLI is very simple, just download a phar file on the server, make it executable. Then you are ready to use it. And some WordPress in has been shipped with WP-CLI.

# Update to the latest WordPress version
$ wp core update

Make sure you have write permissions to the WordPress core files and the updated file can be written by the Web server user (who are running the Web server) afterwards.

A simple method is to execute update command as the root user. This will make the files updated to be owned by the root, you need to reset the ownership and restart the Web server to take effect. What we do here is just to make Web server user have write permissions to these files, remember that.

# Update WordPress as the root
$ sudo wp core update --allow-root

# Reset the ownership to the user who runs the Web server.
$ sudo chown -R <web server user> <wordpress path>

Manual update

If all the above solutions do not work for you, mannual update can be a last resort for your.

Troubleshooting: WP-CLI displays PHP notices when running commands

Issue

When running commands in WP-CLI, it shows a lot of notices like below:

$ wp post list
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; QrctWp has a deprecated constructor in xxxwp-contentpluginsqr-code-taglibqrctQrctWp.php on line 11
PHP Notice:  wp_enqueue_script was called <strong>incorrectly</strong>. Scripts and styles should not be registered or enqueued until the <code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or <code>login_enqueue_scripts</code> hooks. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.3.0.) in xxxwp-includesfunctions.php on line 4231
Notice: wp_enqueue_script was called <strong>incorrectly</strong>. Scripts and styles should not be registered or enqueued until the <code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or <code>login_enqueue_scripts</code> hooks. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.3.0.) in xxxwp-includesfunctions.php on line 4231
...

Solution

Set WP_DEBUG from true to false in wp-config.php of your WordPress.

wp-config.php:

define( 'WP_DEBUG', false );