codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php /** * Define MyClass */ class MyClass { public $public = 'I am a public string'; protected $protected = 'I am a protected string'; private $private = 'I am a private string'; function printString() { echo $this->public . "\n"; echo $this->protected . "\n"; echo $this->private . "\n"; } } $obj = new MyClass(); $obj->printString(); // Shows Public, Protected and Private, pringString() is a public function echo "\n"; echo $obj->public; // Works // echo $obj->protected; Fatal Error as $protected is accessed outside the class and not by an inherited class // echo $obj->private; Fatal Error as $private is accessed outside the class ?>
Private
[
?
]
Run code
Submit