@@ -367,6 +367,14 @@ PHP_METHOD(JsObject, __invoke) {
367367 TRACE (" <" );
368368}
369369
370+ // Implement `__toString` by calling JS `toString` method.
371+ PHP_METHOD (JsObject, __toString) {
372+ // use plain zval to avoid allocating copy of method name
373+ zval method; ZVAL_STRINGL (&method, " toString" , 8 , 0 );
374+ zval *args = NULL ;
375+ call_user_function (EG (function_table), &this_ptr, &method,
376+ return_value, 0 , &args TSRMLS_CC);
377+ }
370378
371379/* Use (slightly thunked) versions of the has/read/write property handlers
372380 * for dimensions as well, so that $obj['foo'] acts like $obj->foo. */
@@ -499,6 +507,8 @@ ZEND_BEGIN_ARG_INFO_EX(node_php_jsobject_call_args, 0, 1/*return by ref*/, 1)
499507 ZEND_ARG_INFO(0 , member)
500508 ZEND_ARG_INFO(0 , args)
501509ZEND_END_ARG_INFO()
510+ ZEND_BEGIN_ARG_INFO_EX(node_php_jsobject_toString_args, 0 , 0 , 0 )
511+ ZEND_END_ARG_INFO()
502512
503513static const zend_function_entry node_php_jsobject_methods[] = {
504514 PHP_ME (JsObject, __construct, NULL , ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
@@ -512,6 +522,7 @@ static const zend_function_entry node_php_jsobject_methods[] = {
512522 PHP_ME (JsObject, __unset, node_php_jsobject_unset_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
513523 PHP_ME (JsObject, __call, node_php_jsobject_call_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
514524 PHP_ME (JsObject, __invoke, NULL , ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
525+ PHP_ME (JsObject, __toString, node_php_jsobject_toString_args, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
515526 ZEND_FE_END
516527};
517528
0 commit comments