5

Working on a small extension for PHP using PHP-CPP, I receive at C++ side, an array with objects and I need retrieve the class name of it. The object Php::Value didn't looks like have any method for it.

Similar as i do at HNI in this extension: https://github.com/mcuadros/bson-hni/blob/master/src/encode.cpp#L86

mcuadros
  • 4,098
  • 3
  • 37
  • 44
  • Any chance you could do something with `__CLASS__` in it? http://www.php.net//manual/en/language.constants.predefined.php – Fluffeh Jun 08 '14 at 11:20
  • `__CLASS__` is for PHP at the object scope. :/ – mcuadros Jun 08 '14 at 11:41
  • Yeah, never tried to do what you want - was hoping you might be able to come up with some trick :) I am curious myself now that you asked it hehe – Fluffeh Jun 08 '14 at 11:42

1 Answers1

4

You are right, there is no special method to determine the classname in C++ in the Php::Value object. The best way to determine the classname is thus to use the Php::call method to call the get_class method in PHP userspace:

std::string classname = Php::call("get_class", object);

Where object is one of the objects in the mentioned array.

Martijn Otto
  • 878
  • 4
  • 21