[PHP] static functions and array_map - why not allowed?
Why can't I use static functions in array_map? Example: ?php class Dummy { static public function T($a) { echo T called with $a\n; return $a+2; } } function t($a) { echo t called with $a\n; return $a*2; } echo 'invoking Dummy::T works fine : ', Dummy::T(3),\n; var_dump(array_map('t',array(1,2))); var_dump(array_map('Dummy::T',array(1,2))); ? Marc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] static functions and array_map - why not allowed?
Marc Weber wrote: Why can't I use static functions in array_map? Example: ?php class Dummy { static public function T($a) { echo T called with $a\n; return $a+2; } } function t($a) { echo t called with $a\n; return $a*2; } echo 'invoking Dummy::T works fine : ', Dummy::T(3),\n; var_dump(array_map('t',array(1,2))); var_dump(array_map('Dummy::T',array(1,2))); do it like this: var_dump(array_map(array(Dummy,T), array(1,2))); ? Marc --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] static functions w/ PHP 4?
Is there any way to have static functions and members of an Object w/ PHP 4.3? Like: class Auth { static var error; static function authenticate() { ... } } Auth::authenticate(); ? The documentation suggests this is possible but I can't seem to make it work. Is this behavior specific to PHP 5? Thanks, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] static functions w/ PHP 4?
On Fri, 2005-12-09 at 14:48, Michael B Allen wrote: Is there any way to have static functions and members of an Object w/ PHP 4.3? Like: class Auth { static var error; static function authenticate() { ... } } Auth::authenticate(); ? The documentation suggests this is possible but I can't seem to make it work. Is this behavior specific to PHP 5? In PHP4 if you don't make use of $this in a class method then it can be used as a static function. PHP4 does not support static class vars, instead you need to use a static function with a static variable. ?php class Auth { function authenticate() { ... } function staticVar( $setValue=null ) { static $myStaticVar = null; if( $setValue !== null ) { $myStaticVar = $setValue; } return $myStaticVar; } } ? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Static functions
Hi, I'm a bit of a newbie to PHP, I've done some stuff in Java/VB/C++ but I'm having a few problems finding info on this issue. Does PHP support something like static functions in Java? for example in Java I can write: public class someClass { public static void someMethod() {} } and then in another file: import someClass; public class anotherClass { someClass.someMethod() } Is there some way to access methods of a class without creating an object in PHP? Right now I just include the file (not using a class) and then call the function but I would like to have it more seperate. Thanks, Leo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static functions
At 22:18 9-2-2003, you wrote: Hi, I'm a bit of a newbie to PHP, I've done some stuff in Java/VB/C++ but I'm having a few problems finding info on this issue. Does PHP support something like static functions in Java? afaik the answer is no, but please do not rely on my pitiful opinion. I only use my classes with one single object, just to keep the code cleaner. See one of the articles on objects, in no particular order: PHP makers on OOP http://www.php.net/oop Lotsotalk http://www.liquidpulse.net/articles/125 knowledgebase http://www.faqts.com/knowledge_base/view.phtml/aid/7569 ZEND Using objects to create an application 1 http://www.zend.com/zend/tut/tutorial-johnson.php ZEND An Introduction to Classes http://www.zend.com/zend/tut/class-intro.php ZEND Overusing OO http://www.zend.com/zend/art/mistake1.php#Heading13 Devarticles http://www.devarticles.com/art/1/241 http://www.devarticles.com/art/1/245 http://www.devarticles.com/art/1/262 http://www.devarticles.com/art/1/285 Devshed Accessing Databases with Class http://www.devshed.com/Server_Side/PHP/Class/ Back to Class http://www.devshed.com/Server_Side/PHP/BackToClass PHPBuilder Classes and PHP http://www.phpbuilder.com/columns/rod19990601.php3 Vamsi: Object Oriented Programming in PHP http://php.vamsi.net/article/3/1 OOP Talk : A slide presentation http://www.sdphp.net/talks/talks/sdphp_class for example in Java I can write: public class someClass { public static void someMethod() {} PHP has no public or private methods import someClass; public class anotherClass { someClass.someMethod() } Is there some way to access methods of a class without creating an object in PHP? afaik you do need to create an object. You can override a function with class y extends (class) x, see the articles for examples Right now I just include the file (not using a class) and then call the function but I would like to have it more seperate. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php