Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-06-02 Thread Jochem Maas
Stanislav Malyshev wrote:
 You'd probably do something along those lines if it were possible:

 ((ParentClass) $child)-virtualMethod();
 
 Looks like bad style to me - why not call child's method and it would,
 if needed, pass control to parent?

yeah, although I could imagine a situation where your stuck needing to calling
parent::method() it smells like bad OO - the same kind of bad smell that people
have been told they should avoid when it comes to wanting static interface 
methods,
function signature changing, etc.

personally I don't mind the smells, I'm not from the straight-jacket OO side of 
the
street. that said I do feel consistency is a worthy goal and therefore it seems 
correct
to enforce straight-jackets all round - given the general direction/mindset of 
php's OO
functionality it seems that calling parent::method() from outside the relevant
$child-method() should be illegal inline with other 'strictness enforcements'.

 

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-06-01 Thread Michael Wallner
Stanislav Malyshev wrote:
the feature actually exists because we need array($obj,
 'parent::func')
 
 Why/when do you need that?

You'd probably do something along those lines if it were possible:

((ParentClass) $child)-virtualMethod();


If you prefer, s/You/One/

Regards,
-- 
Michael

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-06-01 Thread Stanislav Malyshev

You'd probably do something along those lines if it were possible:

((ParentClass) $child)-virtualMethod();


Looks like bad style to me - why not call child's method and it would, 
if needed, pass control to parent?


--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED]  http://www.zend.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-06-01 Thread Richard Lynch


On Fri, June 1, 2007 12:06 pm, Stanislav Malyshev wrote:
 You'd probably do something along those lines if it were possible:

 ((ParentClass) $child)-virtualMethod();

 Looks like bad style to me - why not call child's method and it would,
 if needed, pass control to parent?

Or, if, for some reason, you need to bypass the child's method, and
call only the parent's method of the same name, why not just look up
the class-Parent and then use array(Parent, 'function')

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-31 Thread Stanislav Malyshev
It's already supported, but buggy right now. I don't believe fixing it 
for odd cases will bother anyone.


Well, I'm for one not sure that callback in form array('B', 
'parent::foo') shouldn't error out instead (I know it works now, but it 
never states in the docs it's legal and I don't think it was intended to 
work). Otherwise next thing would be array('B', 'C::foo') and that'd be 
a real mess.


--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED]  http://www.zend.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-31 Thread Stanislav Malyshev

What about array('B', 'self::foo') -- I can see how that's needed to
call the static method, I guess...


But that won't be different from just array('B', 'foo') so you don't 
need self::...

--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED]  http://www.zend.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-31 Thread Richard Lynch
On Thu, May 31, 2007 3:44 pm, Stanislav Malyshev wrote:
 What about array('B', 'self::foo') -- I can see how that's needed to
 call the static method, I guess...

 But that won't be different from just array('B', 'foo') so you don't
 need self::...

Duh.

Sorry.

I somehow had some imaginary instance of 'B' that was involved...

Got lost in the clouds thinking about who needs anything like this at
all.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-31 Thread Marcus Boerger
Hello Richard,

   the feature actually exists because we need array($obj, 'parent::func')

best regards
marcus

Thursday, May 31, 2007, 10:33:54 PM, you wrote:

 On Thu, May 31, 2007 1:06 pm, Stanislav Malyshev wrote:
 It's already supported, but buggy right now. I don't believe fixing
 it
 for odd cases will bother anyone.

 Well, I'm for one not sure that callback in form array('B',
 'parent::foo') shouldn't error out instead (I know it works now, but
 it
 never states in the docs it's legal and I don't think it was intended
 to
 work). Otherwise next thing would be array('B', 'C::foo') and that'd
 be
 a real mess.

 Seems to me that anybody who thinks they need this can lookup the
 parent of B and construct the right array in the first place...

 I'm sure the patch is nifty, but it seems better to me to just error
 out as well.

 What about array('B', 'self::foo') -- I can see how that's needed to
 call the static method, I guess...

 -- 
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?




Best regards,
 Marcus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] [patch] Callbacks bug/change request

2007-05-30 Thread Etienne Kneuss

Hi internals,

It seems that there is a bug in the way some callbacks are handled. For 
instance:


array('B', 'parent::who');

Here, the classname 'B' will only be used for inheritance checks with 
the current scope,
but the actual resolution will be made using the current scope, and 
'parent::who'.


According to Marcus, this is wrong, so here is two patches (+ tests) 
meant for HEAD [1]

and the 5_2 branch (5.2.3) [2].

Thanks for your consideration.

Regards

1: http://patches.colder.ch/Zend/callbacks_HEAD.patch?markup
2: http://patches.colder.ch/Zend/callbacks_5_2.patch?markup

--
Etienne Kneuss
http://www.colder.ch
[EMAIL PROTECTED]

Men never do evil so completely and cheerfully as 
when they do it from a religious conviction.

-- Pascal

Index: ext/standard/tests/general_functions/callbacks_001.phpt
===
RCS file: ext/standard/tests/general_functions/callbacks_001.phpt
diff -N ext/standard/tests/general_functions/callbacks_001.phpt
--- /dev/null   1 Jan 1970 00:00:00 -
+++ ext/standard/tests/general_functions/callbacks_001.phpt 27 May 2007 
21:38:48 -
@@ -0,0 +1,55 @@
+--TEST--
+ZE2 Callbacks of static functions
+--FILE--
+?php
+class A {
+public static function who() {
+echo A\n;
+}
+public static function who2() {
+echo A\n;
+}
+}
+
+class B extends A {
+public static function who() {
+echo B\n;
+}
+}
+class C extends B {
+public function foo() {
+call_user_func(array('parent', 'who'));
+call_user_func(array('C', 'parent::who'));
+call_user_func(array('B', 'parent::who'));
+call_user_func(array('E', 'parent::who'));
+call_user_func(array('B', 'who2'));
+call_user_func(array('A', 'who'));
+call_user_func(array('C', 'who'));
+}
+}
+
+class D {
+public static function who() {
+echo D\n;
+}
+}
+
+class E extends D {
+public static function who() {
+echo E\n;
+}
+}
+
+$o = new C;
+$o-foo();
+?
+===DONE===
+--EXPECT--
+B
+B
+A
+D
+A
+A
+B
+===DONE===
Index: Zend/zend_API.c
===
RCS file: /repository/ZendEngine2/zend_API.c,v
retrieving revision 1.296.2.27.2.30
diff -u -r1.296.2.27.2.30 zend_API.c
--- Zend/zend_API.c 16 May 2007 18:57:15 -  1.296.2.27.2.30
+++ Zend/zend_API.c 27 May 2007 21:38:50 -
@@ -2125,6 +2125,8 @@
mlen = Z_STRLEN_P(callable) - clen - 2;
lcname = zend_str_tolower_dup(Z_STRVAL_P(callable), clen);
/* caution: lcname is not '\0' terminated */
+   zend_class_entry *last_scope = EG(scope);
+   EG(scope) = ce_org;
if (clen == sizeof(self) - 1  memcmp(lcname, self, 
sizeof(self) - 1) == 0) {
*ce_ptr = EG(scope);
} else if (clen == sizeof(parent) - 1  memcmp(lcname, 
parent, sizeof(parent) - 1) == 0  EG(active_op_array)-scope) {
@@ -2132,6 +2134,7 @@
} else if (zend_lookup_class(Z_STRVAL_P(callable), clen, pce 
TSRMLS_CC) == SUCCESS) {
*ce_ptr = *pce;
}
+   EG(scope) = last_scope;
efree(lcname);
if (!*ce_ptr) {
return 0;
Index: Zend/zend_execute_API.c
===
RCS file: /repository/ZendEngine2/zend_execute_API.c,v
retrieving revision 1.331.2.20.2.19
diff -u -r1.331.2.20.2.19 zend_execute_API.c
--- Zend/zend_execute_API.c 27 Apr 2007 08:12:24 -  1.331.2.20.2.19
+++ Zend/zend_execute_API.c 27 May 2007 21:38:53 -
@@ -750,7 +750,8 @@
if ((colon = strstr(fname, ::)) != NULL) {
int clen = colon - fname;
int mlen = fname_len - clen - 2;
-   zend_class_entry **pce, *ce_child = NULL;
+   zend_class_entry **pce, *ce_child = NULL, *last_scope = 
EG(scope);
+   EG(scope) = calling_scope;
if (zend_lookup_class(fname, clen, pce TSRMLS_CC) == 
SUCCESS) {
ce_child = *pce;
} else {
@@ -765,6 +766,7 @@
}
efree(lcname);
}
+   EG(scope) = last_scope;
if (!ce_child) {
zend_error(E_ERROR, Cannot call method %s() or 
method does not exist, fname);
return FAILURE;
Index: Zend/zend_API.c
===
RCS file: /repository/ZendEngine2/zend_API.c,v
retrieving revision 1.433
diff -u -r1.433 zend_API.c
--- Zend/zend_API.c 16 May 2007 18:56:38 -  1.433
+++ Zend/zend_API.c 27 May 2007 15:31:44 -
@@ -2561,7 +2561,11 @@
   

Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-30 Thread Etienne Kneuss

Stanislav Malyshev wrote:
It seems that there is a bug in the way some callbacks are handled. 
For instance:


array('B', 'parent::who');


I'm not sure such thing should be even supported. I.e. I'd expect it 
to try and call method named 'parent::who' in class B, which would 
fail since you can't define such method name. Is there any reason why 
anybody  would really need anything like this?
It's already supported, but buggy right now. I don't believe fixing it 
for odd cases will bother anyone.


According to Marcus, this is wrong, so here is two patches (+ tests) 
meant for HEAD [1]

and the 5_2 branch (5.2.3) [2].

Thanks for your consideration.


First part of the patch changes EG(scope) even though no actual call 
is made. I don't think you should change globals if you are not 
intending to use them. If some value is needed which equals to 
EG(scope) or other value depending on context, I think you should do 
it with variable, not change the global, if possible.
EG(scope) is used by zend_u_fetch_class to get the parent/current class, 
I'm only altering it temporarily before zend_u_fetch_class and restore 
it after that, no harm done.


--
Etienne Kneuss
http://www.colder.ch
[EMAIL PROTECTED]

Men never do evil so completely and cheerfully as 
when they do it from a religious conviction.

-- Pascal

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-30 Thread Stanislav Malyshev
It seems that there is a bug in the way some callbacks are handled. For 
instance:


array('B', 'parent::who');


I'm not sure such thing should be even supported. I.e. I'd expect it to 
try and call method named 'parent::who' in class B, which would fail 
since you can't define such method name. Is there any reason why anybody 
 would really need anything like this?


According to Marcus, this is wrong, so here is two patches (+ tests) 
meant for HEAD [1]

and the 5_2 branch (5.2.3) [2].

Thanks for your consideration.


First part of the patch changes EG(scope) even though no actual call is 
made. I don't think you should change globals if you are not intending 
to use them. If some value is needed which equals to EG(scope) or other 
value depending on context, I think you should do it with variable, not 
change the global, if possible.

--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED]  http://www.zend.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-30 Thread Stanislav Malyshev
EG(scope) is used by zend_u_fetch_class to get the parent/current class, 
I'm only altering it temporarily before zend_u_fetch_class and restore 
it after that, no harm done.


I was speaking about 5.2 patch, didn't check the HEAD one.
--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED]  http://www.zend.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [patch] Callbacks bug/change request

2007-05-30 Thread Etienne Kneuss

Stanislav Malyshev wrote:
EG(scope) is used by zend_u_fetch_class to get the parent/current 
class, I'm only altering it temporarily before zend_u_fetch_class and 
restore it after that, no harm done.


I was speaking about 5.2 patch, didn't check the HEAD one.
Oh, I see now what you mean. I ported the patch to 5_2 with the 
assumption that zend_lookup_class also used EG(scope), but in fact it 
doesn't. I updated the patch[1] which now directly uses 
calling_scope/ce_org instead of the current scope for parent/self 
resolution.


I hope this one better fits your requirements.

Regards

1: http://patches.colder.ch/Zend/callbacks_5_2.patch?markup

--
Etienne Kneuss
http://www.colder.ch
[EMAIL PROTECTED]

Men never do evil so completely and cheerfully as 
when they do it from a religious conviction.

-- Pascal

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php