4

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.
    – Gumbo
    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.

2
  • 1
    This is the only correct answer so far. You don't get error messages about stdClass for the reasons stated by other answers. Commented Oct 26, 2011 at 12:17
  • 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.
    – Schmoove
    Commented Nov 29, 2011 at 11:03
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
  • -1 Incorrect. See my answer below.
    – JW.
    Commented Aug 8, 2011 at 22:24
  • class exists – stdClass and it just doesn't contain mysql_con() method Commented Feb 22, 2012 at 15:14
0

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

phpinfo();

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.

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();

Not the answer you're looking for? Browse other questions tagged or ask your own question.