Re: [PHP-DEV] Fatal error: Call to a member function on a non-object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



please don't post this kind of question to internals. use php-general@xxxxxxxxxxxxxx

Christopher Vogt schreef:
> Hej,
> 
> I use PHP 5.2.6. I am refactoring some code to use more
> object-orientation. I encounter a problem, where the new object-oriented
> version results in a fatal error, where the old array-oriented version
> didn't.
> 
> I fetch records a database. Sometime it happens that a record does not
> exist anymore. Let's assume it's a user, then $user will be NULL.
> 
> echo $user['fullname']; // no error at all, $user['fullname'] === NULL
> 
> Shouldn't this at least trigger a Notice?
> 
> echo $user->get_fullname(); // Fatal error
> 
> I agree this should trigger an error, but a "Fatal error" is a little
> too much, I think. It terminates the script leaving the html-document
> incomplete. I would prefer a "Warning" and NULL instead.

either go back to using arrays or fix your code. your asking for something
to change when you have little idea of why or what it is in the first place.

> 
> Is there any reason against it?

plenty, I suggest taking the time to get a better understanding of OO, the php
implementation and the various related tools it offers (instanceof, "method-chaining",
exceptions, etc, etc).

calling a method on an object that doesn't exist is tantamount to calling a function
which doesn't exist ... both are a fatal error.

> 
> Best regards
> 
> Christopher
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux