Login   Register  
PHP Classes
elePHPant
Icontem

File: example_restricted_access

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Costin Trifan  >  Safe Object  >  example_restricted_access  >  Download  
File: example_restricted_access
Role: Example script
Content type: text/plain
Description: Example page
Class: Safe Object
Dynamically restrict the access to class variables
Author: By
Last change:
Date: 4 years ago
Size: 850 bytes
 

Contents

Class file image Download
<?php
/*
*  RestrictedAccess(true)
*---------------------------------
* Properties can not be added at run-time
*/

class Test extends SafeObject
{
    public function 
DoSomething() { echo 'Doing something...'; }
    public function 
DoSomethingElse() { echo 'Doing something else...'; }
}



$o = new Test();

$o->RestrictedAccess(true)
  ->
AllowedProperties(array('server','username'));


echo 
'RestrictedAccess(true)<br/>-------------------------------<br/>';


// ok
$o->server 'localhost';
echo 
'<br/>server: ' $o->server;

// ok
$o->username 'costin';
echo 
'<br/>username: ' $o->username;

// NOT ok [Error: allowed properties cannot be unset while in restricted mode]
unset($o->username);

// NOT ok [Error: test is not part of the allowed properties]
$o->test 'test';
echo 
'<br/>test: ' $o->test;
?>