non-object Fatal Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

non-object Fatal Error

Post by montecristo »

Hi guys,

I am getting the following error

Fatal error: Call to a member function getcustomerid() on a non-object in C:\Xampp\xampp\htdocs..... on line 54

Basically, I am passing in userid to the customer class. If this customer exists i,e the number is a valid id , the class is created eg. name, address etc. I can then call a function of this class

Code: Select all

$customer = new customer($customerid);
echo $customer->getcustomerid();
echo $customer->getfirstname();
This works fine if the customer id is valid. However if the id is invalid and not a customer id I get the error
Fatal error: Call to a member function getcustomerid() on a non-object.

Basically I need to return some sort of message if the customer id( therefore the customer ) doesn't exist
Any ideas?

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

montecristo wrote:However if the id is invalid and not a customer id I get the error
Fatal error: Call to a member function getcustomerid() on a non-object.
What is $customer in this case? var_dump($customer) can tell.
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Post by montecristo »

In the case of an invalid user id:

{ ["customerid"]=> NULL ["firstname"]=> NULL ["surname"]=> NULL ["queryname"]=> NULL ["branchissued"]=> NULL ["mobile"]=> NULL ["title"]=> NULL ["cardholder"]=> NULL ["address1"]=> NULL ["address2"]=> NULL ["address3"]=> NULL ["address4"]=> NULL ["address5"]=> NULL ["email"]=> NULL ["phone"]=> NULL ["update_firstname"]=> bool(false) ["update_surname"]=> bool(false) ["update_queryname"]=> bool(false) ["update_branchissued"]=> bool(false) ["update_mobile"]=> bool(false) ["update_title"]=> bool(false) ["update_cardholder"]=> bool(false) ["update_address1"]=> bool(false) ["update_address2"]=> bool(false) ["update_address3"]=> bool(false) ["update_address4"]=> bool(false) ["update_address5"]=> bool(false) ["update_email"]=> bool(false) ["update_phone"]=> bool(false) ["customerarray"]=> NULL ["c"]=> NULL }

In the case of a valid user id

{ ["customerid"]=> string(2) "30" ["firstname"]=> string(4) "John" ["surname"]=> string(4) "Smith" ["queryname"]=> NULL ["branchissued"]=> string(3) "DUN" ["mobile"]=> string(8) "79906778" ["title"]=> string(2) "Mr" ["cardholder"]=> string(1) "Y" ["address1"]=> string(8) "50 The Grange" ["address2"]=> string(24) "Main Road Industrial Park" ["address3"]=> string(9) "Dublin 22" ["address4"]=> NULL ["address5"]=> NULL ["email"]=> string(18) "johnsmith@x.ie" ["phone"]=> string(3) "123" ["update_firstname"]=> bool(false) ["update_surname"]=> bool(false) ["update_queryname"]=> bool(false) ["update_branchissued"]=> bool(false) ["update_mobile"]=> bool(false) ["update_title"]=> bool(false) ["update_cardholder"]=> bool(false) ["update_address1"]=> bool(false) ["update_address2"]=> bool(false) ["update_address3"]=> bool(false) ["update_address4"]=> bool(false) ["update_address5"]=> bool(false) ["update_email"]=> bool(false) ["update_phone"]=> bool(false) ["customerarray"]=> NULL ["c"]=> NULL } } ["c"]=> NULL }
Post Reply