PHP : Custom error handler – handling parse & fatal errors

Actually you can handle parse and fatal errors. It is true that the error handler function you defined with set_error_handler() will not be called. The way to do it is by defining a shutdown function with register_shutdown_function(). Here is what I have working in my website: File prepend.php (this file will be prepended to all … Read more

How to catch the fatal error: Maximum execution time of 30 seconds exceeded in PHP

How about trying as PHP documentation (well… at least one of its readers) say: <?php function shutdown() { $a = error_get_last(); if ($a == null) {echo “No errors”;} else {print_r($a);} } register_shutdown_function(‘shutdown’); ini_set(‘max_execution_time’, 1); sleep(3); ?> Have a look at the following links: http://www.php.net/manual/en/function.set-error-handler.php#106061 http://www.php.net/manual/en/function.register-shutdown-function.php

PHP Notice: Undefined offset: 1 with array when reading data

Change $data[$parts[0]] = $parts[1]; to if ( ! isset($parts[1])) { $parts[1] = null; } $data[$parts[0]] = $parts[1]; or simply: $data[$parts[0]] = isset($parts[1]) ? $parts[1] : null; Not every line of your file has a colon in it and therefore explode on it returns an array of size 1. According to php.net possible return values from … Read more

How can I catch a “catchable fatal error” on PHP type hinting?

Update: This is not a catchable fatal error anymore in php 7. Instead an “exception” is thrown. An “exception” (in scare quotes) that is not derived from Exception but Error; it’s still a Throwable and can be handled with a normal try-catch block. see https://wiki.php.net/rfc/throwable-interface E.g. <?php class ClassA { public function method_a (ClassB $b) … 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

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)