IsSMTP() in phpmailer function - php

****Fatal error: Call to a member function IsSMTP() on a non-object****
I get this error in my program. I have tried $mail=isSMTP(true);
Please help me understand why this error occurs and how I can resolve this error

You need to create an instance of an object before you call methods on it, and post your whole code when asking a question on SO.

Related

how spl_autoload_register works internally

what i know is spl_autoload_register function is lib function which takes callback function which gets executed when error 'file not found'(fatal) occurs while using new keyword and that include that specific class or rather file.
so my question is how does it handle fatal error being on top of the code if suppose it can handle fatal error.
and my think of error or exception handle is you must know error or exception is that we must know before so that we can include this in the block try,throw, catch.
so my question is how does it catches error being on top of the code.
i am beginner any help appreciated.
thankyou

Invoking wsclient_service_load function in Drupal

I'm trying to invoke this function in a Drupal custom module:
wsclient_service_load('my_web_service');
And it returns an error:
Fatal error: Call to undefined function wsclient_service_load() in...
But if I invoke the same function from page.tpl.php it works fine.
I must being missing something really basic.
Hope someone can enlight me.
Thanks

PHP class fatal error call to undefined function stuck globally

In debugging some code I've mistakenly made a call to a member function on a non-object, giving the expected Call to a member function get() on a non-object in /path/to/file.php on line X. I'm accustomed to this, while PHP isn't my favorite language I've been working with it for years. What's confusing me is that when I remove the offending code (I'm using version control and resetting to what should be a working state prior to the bad call), I still get the error. Is it possible for this error to have corrupted an in-memory (I'm using APC object caching). I feel like the answer might be "yes, maybe", however I honestly don't think that explains the problem and am wondering if anyone else has encountered something similar? Is there a method to somehow reset this PHP class object?

Storing a PHP exception object in a database

I have need to store a PHP Exception object in a mysql column. It's for an offline error logging system. Usually I would just serialize() the Exception object and be done with it, but half the time, when trying to do that, I get the following error:
Fatal error: Uncaught exception 'Exception' with message
'Serialization of 'Closure' is not allowed'
I am not sure how to get this to work consistently. I will greatly appreciate anyone who has an answer to this problem.
Thanks.
The exception object to be logged contains an instance of Closure class, PHP's implementation of anonymous functions and closure. Apparently anonymous functions cannot be serialized.
You need to investigate your exception classes and see if any of them is supposed to contain them. Normally, exception classes shouldn't have an anonymous function as property.
This reproduces the same error message as your case:
$exception = new Exception('BOO');
$anonymousFunction = function() { echo 'blah'; };
$exception->anonymousFunction = $anonymousFunction;
serialize($exception);
So dig in through your code, your framework's code, your library's code, and try to find out which exception class did have an anonymous function as class property, who assigned them, why - and then you should be able to create a special case for it.
Hope this helps.
http://php.net/manual/en/function.set-error-handler.php
here's the global error handler definition function. you can define a global error handler and make it write the error description to the database.
And the structure of the exception class :
http://php.net/manual/en/class.exception.php

Catching "Call to a member function foo() on a non-object" errors

Is there a way to catch Call to a member function foo() on a non-object in PHP? It does not sound that serious (as far as fatal errors go), but the shutdown function does not seem to be called at all (PHP 5.3, Debian).
Update:
How to prevent such errors is really not the point. Sure, one should check for null whenever that is an expected possibility, but littering every single object member function reference with error checking code would result in bloated and unreadable code. Hunting down the occassional error based on the logs is fine - the problem is that logs are not very useful for fatal errors. Using a shutdown function would solve that nicely, but I can't get it to work with this specific type of error; which seems strange to me, because it is not an error which would leave the PHP interpreter in a particularly messy state.
I hope this does not sound silly - but you should make sure you know what you are working with. Use instanceof or is_object where you need - or fix the source of the problem - why is that variable not an object in the first place?
I suggest to just ensure, that it is an object. Using methods/functions you can use type hints
public function x (myClass $object) {
$object->foo();
}
else you may use is_object(). At the end such a message sounds like there is a bug within you application, that should be fixed before release, or -- if such a situation can occur by design -- verify the type (is_object() (see above) or !is_null($obj) or something like that) before trying to call something, that does not exist.

Categories