From:             vito_web at yahoo dot com
Operating system: Linux
PHP version:      5.3.0
PHP Bug Type:     Class/Object related
Bug description:  I have access to the private attributes of a give class

Description:
------------
<?php
/**
 * Define MyClass
 */
class MyClass
{
    public $public = 'Public';
    protected $protected = 'Protected';
    private $private = 'Private';

    function printHello()
    {
        echo $this->public;
        echo $this->protected;
        echo $this->private;
    }
}

$obj = new MyClass();
echo $obj->public; // Works
//echo $obj->protected; // Fatal Error
//echo $obj->private; // Fatal Error
$obj->printHello(); // Shows Public, Protected and Private


/**
 * Define MyClass2
 */
class MyClass2 extends MyClass
{
    // We can redeclare the public and protected method, but not 
private
    protected $protected = 'Protected2';

    function printHello()
    {
        echo $this->public;
        echo $this->protected;
        echo $this->private;
    }
}

$obj2 = new MyClass2();
echo $obj2->public; // Works
echo $obj2->private = "Hacked";
echo $obj2->private; // Undefined
//echo $obj2->protected; // Fatal Error
$obj2->printHello(); // Shows Public, Protected2, Undefined

?>

Expected result:
----------------
PHP Fatal error:  Cannot access private property MyClass2::$private 
in......

Actual result:
--------------
PublicPublicProtectedPrivatePublicHackedHackedPublicProtected2Hacked

-- 
Edit bug report at http://bugs.php.net/?id=49702&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49702&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49702&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49702&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49702&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49702&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49702&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49702&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49702&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49702&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49702&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49702&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49702&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49702&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49702&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49702&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49702&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49702&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49702&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49702&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49702&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49702&r=mysqlcfg

Reply via email to