Understanding PHP Errors: BadMethodCallException
×


Understanding PHP Errors: BadMethodCallException

868

In usual day of a developer’s life PHP error, "BadMethodCallException: Call to undefined method" error occurs when you are trying to call an undefined method of a class in PHP script.

Let's review an example below

For Instance:-

class Test {
}
var_dump(Test::all( ));

The above code will throw "BadMethodCallException: Call to undefined method" because the script is trying to call the all method which does not exist in the Test class.

To resolve or avoid such kind of exception one must ensure that called method is defined in the class called through the script. Also, in order to resolve the issue, you can implement the _call magic method to handle calls to undefined methods in your PHP scripts.

However, this approach should be considered as last resort to the issue.

Related PHP Error

Understanding PHP Errors: BadMethodCallException



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments