Posts: 876
Name: Matt Pealing
Location: England, north west
|
I'm getting to grips with Object Oriented PHP, but there's something I really don't understand about inheritance.
See this script:
PHP Code:
<?php
/** * Define MyClass */ class MyClass { public $public = 'Public'; protected $protected = 'Protected'; private $private = 'Private'; }
$obj = new MyClass; echo $obj->public;
?>
I can access the public property fine, but when I try to echo 'protected' or 'private', I just see a blank screen!
I thought they would all be accessible from this object? I thought protected wouldn't be accessible from an object that wasn't of 'MyClass' (or any of its parents / children) and that private would only be accessible from an object of MyClass.
I'm guessing I have the wrong idea?
Also, I very rarely see any error messages with and OOP scripts! I have both XAMPP and MAMP installed on my Mac, but I mostly just see a blank screen when something goes wrong.
Do I need to change the error settings for my PHP installation or is this normal behaviour?
|