oop - PHP differences between abstract public static vs abstract static public -


i mistakenly defined method signature as

abstract static public function mapattributekeys(array $attributes)

it works properly, while i'm refactoring code, see not looks , should following according habit.

abstract public static function mapattributekeys(array $attributes)

i little surprised how these 2 works. thinking above syntax wrong syntax.

so these 2 working. there reason why definition not stricted ? or pattern match here ?

my actual aim learn why these flexibility exist ? there special approach or implementation trick exist ?

updated :

i saw https://stackoverflow.com/a/10740068/1147648 explanation meaningful.

an abstract function never static, in kind of language 

if true, why there implementation exist ?

even in symfony validator loader.

https://github.com/symfony/validator/blob/master/tests/mapping/loader/abstractstaticmethodloader.php

abstract, public , static modifier keywords function definition. there's no specific order in need stated, they're of equivalent importance , not rely on or interact 1 in way.

a big, blue, round ball same blue, round, big ball.


an abstract function never static, in kind of language

jein.

the use of abstract force subclass implement particular method, so parent class/users of parent class can rely on method being there:

abstract class foo {     abstract public function bar(); }  function baz(foo $foo) {     $foo->bar(); } 

baz doesn't know specific instance of foo it'll receive, can sure it'll have bar method.

now, static methods can called on class itself:

foo::bar(); 

if you're writing this, you know class you're calling bar on. you're not going substitute foo here; foo hardcoded, not variable in case $foo.* so... know you're getting , don't need abstract base class enforce interface you.

* true if use string variable dynamically change class name. point can't type hint against that, you're on own. class interfaces, includes abstract methods, become useful , interesting type hinting, can done object instances.

it's possible enforce static methods defined on child classes, doesn't make whole lot of practical sense.


Comments

Popular posts from this blog

Redirect to a HTTPS version using .htaccess -

Unlimited choices in BASH case statement -

javascript - jQuery: Add class depending on URL in the best way -