Is there some way to declare static and dynamic methods with same name in PHP?
3
-
You should elaborate. It is not clear.Sougata Bose– Sougata Bose2015-07-28 13:04:36 +00:00Commented Jul 28, 2015 at 13:04
-
possible duplicate of PHP - is it possible to declare a method static and nonstaticlorenzo-s– lorenzo-s2015-07-28 13:06:46 +00:00Commented Jul 28, 2015 at 13:06
-
This is a perfectly fine question and I just found it on google while asking myself the very same thing.lhermann– lhermann2018-12-05 03:32:41 +00:00Commented Dec 5, 2018 at 3:32
Add a comment
|
1 Answer
No. You cannot declare 2 functions with the same name, even if they have different footprint. You'll get a fatal error like this:
PHP Fatal error: Cannot redeclare Classname::methodname() in yourfile.php
2 Comments
Dmytro Zarezenko
But as I know in the PHP 7 you can't call static function from dynamic context, maybe we will have this declaration possibility after this changes?
Nanne
Why? You can't call methods that require 1 parameter without the parameter, but that doesn't mean you can declare methods without and with one. So calling a certain footprint might be changing, declaring them still isn't in the books.