PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Chris Lam   Gettable   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: test drive
Class: Gettable
Make protected class properties accessible
Author: By
Last change: Removed leading underscore for the private attribute.
Date: 14 years ago
Size: 491 bytes
 

Contents

Class file image Download
<?php

require_once 'Gettable.cls.php';

class
MyClass extends Gettable
{
    protected
$readonly = "1";

    protected
$_reallyPrivate1 = "2";
    private
$reallyPrivate2 = "3";
}

$obj = new MyClass;

echo
$obj->readonly; // ok
echo $obj->_reallyPrivate1; // Fatal error
echo $obj->reallyPrivate2; // Fatal error

var_dump(isset($obj->readonly)); // true
var_dump(isset($obj->_reallyPrivate1)); // false
var_dump(isset($obj->reallyPrivate2)); // false