Skip to content

Instantly share code, notes, and snippets.

@3F
Created January 10, 2014 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3F/8355262 to your computer and use it in GitHub Desktop.
Save 3F/8355262 to your computer and use it in GitHub Desktop.
Java7 & PHP 5.5. LSP / properties & methods
/* **** 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
@3F
Copy link
Author

3F commented Jan 10, 2014

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