Skip to content

Instantly share code, notes, and snippets.

@bwg
Last active August 29, 2015 13:57
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 bwg/9623334 to your computer and use it in GitHub Desktop.
Save bwg/9623334 to your computer and use it in GitHub Desktop.
fun with php
<?php
abstract class Base {
protected $name = 'Base';
}
class Foo extends Base {
// defining $name here will properly fatal on access violation
// protected $name = 'Foo';
public function __construct() {
// however, setting it here is all good!
$this->name = 'Foo';
}
}
class Bar extends Base {
public static function fooName() {
$foo = new Foo();
echo $foo->name."\n";
}
}
Bar::fooName(); // Foo
$foo = new Foo();
print_r($foo);
/**
Foo Object
(
[name:protected] => Foo
)
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment