Method Visibility Class.
Method Visibility Class methods must be defined with public, private, or protected. Methods without any declaration are defined as public. // Define MyClass class MyClass { // Contructors must be public public function __construct() { } // Declare a public method public function MyPublic() { } // Declare a protected method protected function MyProtected() { } // Declare a private method private function MyPrivate() { } // This is public by default function Foo() { $this->MyPublic(); $this->MyProtected(); $this->MyPrivate(); } } // MyClass $myclass = new MyClass; $myclass->MyPublic(); // Works! $myclass->MyProtected(); // Fatal Error $myclass->MyPrivate(); // Fatal Error $myclass->Foo(); // Public, Protected and Private work // Define MyClass2 class MyClass2 extends MyClass { // This is public by default function Foo2() { $this->MyPublic(); $this->MyProtected(); $this->MyPrivate(); // Fatal Error } } // MyClass2 $myclass2 = new MyClass2; $myclass2->MyPublic(); // Works! $myclass2->Foo2(); // Public and Protected work, not Private.
Thanks for sharing this information.
ReplyDeleteweb design agency uk
web design agency uk
web design agency uk
web design agency uk
web design agency uk