johnsmith153 Posted November 20, 2010 Share Posted November 20, 2010 There is a name for this, not sure what it's called: class ClassName { function display ($a, $b) { return $a::$b; } } class OtherClass { function show() { echo "Well Done"; } } ClassName::display("OtherClass", "show"); Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/ Share on other sites More sharing options...
trochia Posted November 20, 2010 Share Posted November 20, 2010 I'm confused...can you outline the goal? What "else if", would be involved? (would sure help) Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/#findComment-1137008 Share on other sites More sharing options...
Daniel0 Posted November 20, 2010 Share Posted November 20, 2010 You can do it like this: class ClassName { function display ($a, $b) { return call_user_func($a, $b); } } or class ClassName { function display ($a, $b) { return $a::$b(); } } Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/#findComment-1137010 Share on other sites More sharing options...
johnsmith153 Posted November 20, 2010 Author Share Posted November 20, 2010 Brilliant, Thanks. That was a bit obvious I suppose - I thought I read somehwere you couldn't do that ($class::$method) (didn't even try it in action to be honest). Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/#findComment-1137015 Share on other sites More sharing options...
johnsmith153 Posted November 20, 2010 Author Share Posted November 20, 2010 Actually, this doesn't seem to work - neither option. I responded before without testing. Can it be done? Does it matter if it is a parent/child or if static/instantiated?? Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/#findComment-1137020 Share on other sites More sharing options...
johnsmith153 Posted November 20, 2010 Author Share Posted November 20, 2010 I get this: Warning: call_user_func(User) [function.call-user-func]: First argument is expected to be a valid callback in xxx on line 58 ?? Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/#findComment-1137030 Share on other sites More sharing options...
johnsmith153 Posted November 20, 2010 Author Share Posted November 20, 2010 actually, it's this: call_user_func ( array($a, $b) ); Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/#findComment-1137039 Share on other sites More sharing options...
Daniel0 Posted November 20, 2010 Share Posted November 20, 2010 Sorry, yes. The callback must be an array. See: http://php.net/callback Quote Link to comment https://forums.phpfreaks.com/topic/219255-oop-can-i-do-this-in-php-not-53/#findComment-1137109 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.