Fatal error: Class ‘SoapClient’ not found

Diagnose Look up the following inside your script file phpinfo(); If you can’t find Soap Client set to enabled like so: Fix Do the following: Locate php.ini in your apache bin folder, I.e Apache/bin/php.ini Remove the ; from the beginning of extension=php_soap.dll Restart your Apache server Look up your phpinfo(); again and check if you … Read more

PHP Fatal error: Cannot redeclare class

You have a class of the same name declared more than once. Maybe via multiple includes. When including other files you need to use something like include_once “something.php”; to prevent multiple inclusions. It’s very easy for this to happen, though not always obvious, since you could have a long chain of files being included by … Read more

Weird PHP error: ‘Can’t use function return value in write context’

This also happens when using empty on a function return: !empty(trim($someText)) and doSomething() because empty is not a function but a language construct (not sure), and it only takes variables: Right: empty($someVar) Wrong: empty(someFunc()) Since PHP 5.5, it supports more than variables. But if you need it before 5.5, use trim($name) == false. From empty … Read more

PHP Fatal error: Using $this when not in object context

In my index.php I’m loading maybe foobarfunc() like this: foobar::foobarfunc(); // Wrong, it is not static method but can also be $foobar = new foobar; // correct $foobar->foobarfunc(); You can not invoke the method this way because it is not a static method. foobar::foobarfunc(); You should instead use: $foobar->foobarfunc(); If however, you have created a … Read more

How do I catch a PHP fatal (`E_ERROR`) error?

Log fatal errors using the register_shutdown_function, which requires PHP 5.2+: register_shutdown_function( “fatal_handler” ); function fatal_handler() { $errfile = “unknown file”; $errstr = “shutdown”; $errno = E_CORE_ERROR; $errline = 0; $error = error_get_last(); if($error !== NULL) { $errno = $error[“type”]; $errfile = $error[“file”]; $errline = $error[“line”]; $errstr = $error[“message”]; error_mail(format_error( $errno, $errstr, $errfile, $errline)); } } … Read more