Skip to content

Instantly share code, notes, and snippets.

@taq
Created June 3, 2013 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taq/5699377 to your computer and use it in GitHub Desktop.
Save taq/5699377 to your computer and use it in GitHub Desktop.
Stupid PHP static variables behaviour
<?php
class A {
public static $name = null;
}
A::$name = "a";
class B extends A {
}
B::$name = "b";
// both return b!
echo A::$name."\n";
echo B::$name."\n";
?>
@viniciusgati
Copy link

Assim fica feio?

    class A {
        public static $name = "a";
    }

    class B extends A {
        public static $name = "b";
    }

    // both return b!
    echo A::$name."\n";
    echo B::$name."\n";

@taq
Copy link
Author

taq commented Jun 5, 2017

Depois de 4 anos que vejo o comentário ... :-p

Na verdade, @viniciusgati, aí não leva em conta a herança, pois você está declarando novamente todas as variáveis na classe filha ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment