Create a PHP object given a typename and call the ctor, optionally passing up to 2 arguments
| 393 | |
| 394 | // Create a PHP object given a typename and call the ctor, optionally passing up to 2 arguments |
| 395 | static |
| 396 | void createObject(const char* obj_typename, zval* return_value, int nargs = 0, zval* arg1 = nullptr, zval* arg2 = nullptr) { |
| 397 | /* is there a better way to do that on the stack ? */ |
| 398 | zend_string *obj_name = zend_string_init(obj_typename, strlen(obj_typename), 0); |
| 399 | zend_class_entry* ce = zend_fetch_class(obj_name, ZEND_FETCH_CLASS_DEFAULT); |
| 400 | zend_string_release(obj_name); |
| 401 | |
| 402 | if (! ce) { |
| 403 | php_error_docref(nullptr, E_ERROR, "Class %s does not exist", obj_typename); |
| 404 | RETURN_NULL(); |
| 405 | } |
| 406 | |
| 407 | object_and_properties_init(return_value, ce, nullptr); |
| 408 | zend_function* constructor = zend_std_get_constructor(Z_OBJ_P(return_value)); |
| 409 | zval ctor_rv; |
| 410 | zend_call_method(Z4_OBJ_P(return_value), ce, &constructor, nullptr, 0, &ctor_rv, nargs, arg1, arg2); |
| 411 | zval_dtor(&ctor_rv); |
| 412 | if (EG(exception)) { |
| 413 | zend_object *ex = EG(exception); |
| 414 | EG(exception) = nullptr; |
| 415 | throw PHPExceptionWrapper(ex); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | static |
| 420 | void throw_tprotocolexception(const char* what, long errorcode) { |
no test coverage detected