>"Marcus B�Rger" <[EMAIL PROTECTED]> escreveu na mensagem
news:[EMAIL PROTECTED]
>
> The patch doesn't compile (always use confugure --enable-maintainer-zts).
> Then you assume that every class has a function to_string(), this is not
what
> we want.
>
> --
> Best regards,
> Marcus mailto:[EMAIL PROTECTED]
>
Marcus,
1. I tried to learn how ZE2 works in 5 hours to write this patch... Sorry. I
even didn't know how ZE1 works...
2. First I tried with get_method handler but then I didn't know how to call
the method with the resulting zend_function union. So I decided to use
"call_user_function" directly since if the method doesn't exist FALSE will
be returned and the default operation will be done. The __destruct method
works the same way...
3. Classes that don't implement the to_string() method will have the default
PHP behavior. They don't need to implement to_string(). The __destruct
method works the same way...
4.I compiled it with --enable-maintainer-zts and it worked. It compiles with
or without --enable-maintainer-zts.
I'm using PHP5-200308030330, with the CLI sapi, and now the configure line
is:
./configure --enable-debug --enable-maintainer-zts --enable-cli
Best regards,
Cristiano Duarte
PS: the patch file needs to be applied inside ./Zend
> Hello Cristiano,
>
> Sunday, August 3, 2003, 5:33:25 AM, you wrote:
>
> CD> I made a patch to the latest PHP5-CVS wich implements this hook. I
think
> CD> it's useful to make a meaningful object stringfied value.
>
> CD> Can anyone verify it and maybe commit it to CVS ?
>
> CD> --- zend.c 2003-07-30 14:07:36.000000000 -0300
> CD> +++ zend.c.new 2003-08-03 00:27:43.000000000 -0300
> CD> @@ -227,10 +227,24 @@
> CD> if (expr->value.obj.handlers->cast_object) {
> CD> TSRMLS_FETCH();
> CD> expr->value.obj.handlers->cast_object(expr, expr_copy, IS_STRING,
0
> CD> TSRMLS_CC);
> CD> } else {
> - expr_copy->>value.str.val = (char *) emalloc(sizeof("Object id #")-1
+
> CD> MAX_LENGTH_OF_LONG);
> - expr_copy->>value.str.len = sprintf(expr_copy->value.str.val, "Object
id
> #%ld", (long)expr->>value.obj.handle);
> CD> + //call to_string method
> CD> + zval *fname, *retval;
> CD> + MAKE_STD_ZVAL(fname);
> CD> + ZVAL_STRING(fname, "to_string", 1);
> CD> + TSRMLS_FETCH();
> CD> + if (call_user_function_ex(NULL, &expr, fname, &retval, 0, NULL,
0,
> CD> NULL TSRMLS_CC) == SUCCESS) {
> CD> + if (Z_TYPE_P(retval) != IS_STRING) {
> CD> + convert_to_string(retval);
> CD> + }
> CD> + ZVAL_STRINGL(expr_copy, Z_STRVAL_P(retval),
Z_STRLEN_P(retval),
> CD> 1);
> CD> + zval_ptr_dtor(&retval);
> CD> + } else {
> CD> + Z_STRVAL_P(expr_copy) = (char *)
> CD> emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG);
> CD> + Z_STRLEN_P(expr_copy) =
> CD> sprintf(Z_STRVAL_P(expr_copy), "Object id #%ld",
> CD> (long)Z_OBJ_HANDLE_P(expr));
> CD> + }
> CD> + zval_ptr_dtor(&fname);
> CD> }
> CD> #if 0
> CD> /* FIXME: This might break BC for some people */
> CD> expr_copy->value.str.len = sizeof("Object")-1;
>
>
> CD> Thanx,
>
> CD> Cristiano Duarte.
>
> CD> "Cristiano Duarte" <[EMAIL PROTECTED]> escreveu na mensagem
> CD> news:[EMAIL PROTECTED]
> >> Sorry guys,
> >>
> >> > $o = new xxx();
> >> should be $o = new my_object();
> >>
> >> And if there is a way to hook into zend_standard_class (stdClass) what
> CD> would
> >> make all objects inherit the to_string method, it would be great !
> >>
> >> Cristiano Duarte
> >>
> >> "Cristiano Duarte" <[EMAIL PROTECTED]> escreveu na mensagem
> >> news:[EMAIL PROTECTED]
> >> > Hi internals,
> >> >
> >> > Is there a way to hook the cast_object handler in userspace ? What I
> CD> want
> >> is
> >> > a default "to_string" method called when I do something like:
> >> >
> >> > class my_object extends class_with_default_to_string_method {
> >> > private $value = "Hello";
> >> > public function to_string() { //overhiding default to_string wich
> >> prints
> >> > "Object id #n"
> >> > return $this->value;
> >> > }
> >> > }
> >> >
> >> > $o = new my_object();
> >> > echo $o;
> >> >
> >> > or:
> >> >
> >> > $o = new xxx();
> >> > echo "My stringfied value is=$o";
> >> >
> >> > Thanx,
> >> >
> >> > Cristiano Duarte
> >> >
> >> >
> >>
> >>
>
>
>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php