Created
January 10, 2014 14:39
-
-
Save 3F/8355262 to your computer and use it in GitHub Desktop.
Java7 & PHP 5.5. LSP / properties & methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* **** JAVA ******************************** */ | |
class A | |
{ | |
public String p = "from A"; | |
public String m() | |
{ | |
return this.p; // or simple p | |
} | |
} | |
class B extends A | |
{ | |
public String p = "from B"; | |
} | |
... | |
B b = new B(); | |
System.out.println(b.m()); // from A | |
/* **** PHP ******************************** */ | |
class A | |
{ | |
public $p = "from A"; | |
public function m() | |
{ | |
return $this->p; | |
} | |
} | |
class B extends A | |
{ | |
public $p = "from B"; | |
} | |
$b = new B(); | |
echo $b->m(); // from B | |
/* **** JAVA ******************************** */ | |
class A | |
{ | |
public String p(){ return "from A"; } | |
public String m() | |
{ | |
return this.p(); // or simple p() | |
} | |
} | |
class B extends A | |
{ | |
public String p(){ return "from B"; } | |
} | |
... | |
B b = new B(); | |
System.out.println(b.m()); // from B | |
/* **** PHP ******************************** */ | |
class A | |
{ | |
public function p(){ return "from A"; } | |
public function m() | |
{ | |
return $this->p(); | |
} | |
} | |
class B extends A | |
{ | |
public function p(){ return "from B"; } | |
} | |
$b = new B(); | |
echo $b->m(); // from B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/3F/8357145