php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #35822 print_r displays private declared objects
Submitted: 2005-12-27 23:38 UTC Modified: 2006-01-03 18:39 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mattias dot segerdahl at bitcom dot se Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.1.1 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mattias dot segerdahl at bitcom dot se
New email:
PHP Version: OS:

 

 [2005-12-27 23:38 UTC] mattias dot segerdahl at bitcom dot se
Description:
------------
print_r($Class) displays private/protected..
     

Reproduce code:
---------------
<?php 
    class foo { 
     
        private $bar = array(); 
        protected $foobar = array();
		
        public function __construct() { 
            $this->bar['blah'] = 'asfdsdf'; 
			$this->foobar['blah'] = '0as87d';
        } 
    } 
     
    try { 
        $f = new foo(); 
        print_r($f);
    } catch (exception $e) { 
        die($e->getMessage()); 
    } 
?>

Expected result:
----------------
foo Object ( [bar:private] => Array ( [blah] => ) [foobar:protected] => Array ( [blah] => ) ) 

Actual result:
--------------
foo Object ( [bar:private] => Array ( [blah] => asfdsdf ) [foobar:protected] => Array ( [blah] => 0as87d ) ) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-27 23:49 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2005-12-28 11:12 UTC] mattias dot segerdahl at bitcom dot se
http://www.php.net/manual/ says:

print_r() and var_export() will also show protected and private properties of objects with PHP 5, on the contrary to var_dump().

Ok, i'm game with that, no biggie, I still believe it's the wrong arpoch, print_r and var_export should only show private/protected if used within the class.

But, let's look at the documentation that you refered me to. Reading it, it belive that var_dump would not report these, so, I had a look there as well..

From var_dump:

In PHP 5 only public, private and protected properties of objects will be returned in the output.
 [2005-12-28 11:39 UTC] tony2001@php.net
That's how they should work, this is expected behaviour.
 [2005-12-28 11:47 UTC] mattias dot segerdahl at bitcom dot se
Manual entries for var_dump and print_r contradicts eachother, this behaviour is not to be expected. Please follow your own words and read the manual before setting bug to bogus.
 [2006-01-03 18:39 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 15:01:29 2024 UTC