0

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

3
  • You should elaborate. It is not clear. Commented Jul 28, 2015 at 13:04
  • possible duplicate of PHP - is it possible to declare a method static and nonstatic Commented 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. Commented Dec 5, 2018 at 3:32

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.