0

Is there some way to declare static and dynamic methods with same name in PHP?

Dmytro Zarezenko
  • 10,526
  • 11
  • 62
  • 104
  • You should elaborate. It is not clear. – Sougata Bose Jul 28 '15 at 13:04
  • possible duplicate of [PHP - is it possible to declare a method static and nonstatic](http://stackoverflow.com/questions/11331616/php-is-it-possible-to-declare-a-method-static-and-nonstatic) – lorenzo-s Jul 28 '15 at 13:06
  • This is a perfectly fine question and I just found it on google while asking myself the very same thing. – lhermann Dec 05 '18 at 03:32

1 Answers1

2

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

Nanne
  • 64,065
  • 16
  • 119
  • 163
  • 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? – Dmytro Zarezenko Jul 28 '15 at 13:43
  • 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. – Nanne Jul 28 '15 at 16:41