Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- **Define MyClass
- */
- class MyClass
- {
- // Declare a public constructor
- public function __construct() {}
- // Declare a public method
- public function MyPublic() {}
- // Declare a proctected method
- proctected function Myproctected() {}
- // declare a private method
- private function MyPrivate() {}
- // This is public
- function Foo()
- {
- $this->MyPublic();
- $this->Myproctected();
- $this->MyPrivate();
- }
- }
- $myclass = new MyClass;
- $myclass->MyPublic();//works
- $myclass->Myproctected();// Fatal Error
- $myclass->MyPrivate();// Fatal Error
- $myclass->Foo();// Public, Protected and Private work
- /**
- * Define MyClass
- */
- class MyClass2 extends MyClass
- {
- // This is public
- function Food2()
- {
- $this->MyPublic();
- $this->Myproctected();
- $this->MyPrivate();// Fatal Error
- }
- }
- $myclass = new MyClass2;
- $myclass->MyPublic();// works
- $myclass->Foo2();// Public and Protected work, not Private
- class Bar
- {
- public function test() {
- $this->testPrivate();
- $this->testPublic();
- }
- public function testPublic() {
- echo "bar::testPublic\n";
- }
- private function testPrivate() {
- echo "Bar::testPrivate\n";
- }
- }
- class Foo extends Bar
- {
- public function testPublic() {
- echo "Foo::testPublic\n";
- }
- private function testPrivate() {
- echo "Foo::testPrivate\n";
- }
- }
- $myFoo = new Foo();
- $myFoo->test();// Bar::testPrivate
- $myFoo->test();// Foo::testPublic
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement