View Single Post
Old 04-20-2008, 06:43 PM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Set the visibility to either private or protected. Then to allow reading the value you can use a public method (function) or hook into the __get method.

PHP Code:
class MyClass
{
    protected 
$var;
    
    
// ...

    
public function getVar()
    {
        return 
$this->var;
    }
    
// or
    
public function __get($property)
    {
        if (
$property === 'var')
            return 
$this->var;
    }

Salathe is offline  
Reply With Quote