5

I get an error that says

Fatal error: Call to undefined method stdClass::mysql_con() in ........../.../includes/script/import.php on line 68.

Line 68 corresponds to:

if(!$ip2c->mysql_con())

I do have a require_once() statement at the beginning of my script

What could be the problem here?

Thanks

3
  • 2
    The problem is that $ip2c is probably not that what you expect it to be. Commented Oct 14, 2009 at 19:38
  • How $ip2c is created? Please give a code sample Commented Oct 14, 2009 at 19:39
  • If your "$ip2c" value is from a query, make sure that a value is indeed returned. Commented Jul 7, 2017 at 17:24

5 Answers 5

12

Dusoft says it could mean:

  • $ip2c object does not exist,

    Which is not correct because you would get a different error "Fatal error: Call to a member function mysql_con() on a non-object"

He also says it could mean:

  • mysql_con function is not part of the class you are trying to call

    Which is true but not so helpful cos its very difficult to add methods to stdClass.

Additionally it could be to do with serialisation quote:

  • This error is normally thrown when a class instance has been serialised to disk, then re-read/deserialised in another request but the class definition has not been loaded yet, so PHP creates it as an "stdClass" (standard class.)

Or most likely, I think:

  • the $ip2c variable was not an object and then php silently cast it to become stdClass somewhere in the code above.

    This could happen if you directly assign a property on it.

Like:

 $ip2c = null;
 
 //php casts $ip2c to 'stdClass'
 $ip2c->foo = bah;
 
 //Fatal error: Call to undefined method stdClass::mysql_con() in...
 $ip2c->mysql_con();

See a better example here.

Sign up to request clarification or add additional context in comments.

2 Comments

This is the only correct answer so far. You don't get error messages about stdClass for the reasons stated by other answers.
I notices that when throwing an exception within a PHP object, my object turned into NULL. I gave up trying to figure out why this happens.
1

it means that either $ip2c object does not exist or mysql_con function is not part of the class you are trying to call.

2 Comments

-1 Incorrect. See my answer below.
class exists – stdClass and it just doesn't contain mysql_con() method
0

I think this happen because "extension=php_mysql.dll" extension isn't loaded in php.ini. Take a look with

phpinfo();

Comments

0

It could be incorrect code. I once managed to get that error when I had this line of code:

if ($myObj->property_exists('min')){
    // do something
}

Which resulted in error line like this:

PHP Fatal error: Call to undefined method stdClass::property_exists() in myFile.php on line ###

I later fixed the line to:

if (property_exists($myObj, 'min')) {
    // do something
}

So check for that possibility as well.

Comments

0

Most likely the object does not exist. Please show us the code of how you created it. If you are using it within another class (maybe creating it in the __construct function for example), using:

$ip2c = new Class;

Won't cut it. Instead do:

$this->ip2c = new Class;

and then

$this->ip2c->mysql_con();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.