php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24391 output of private class variable doesn't show an error
Submitted: 2003-06-29 15:35 UTC Modified: 2003-06-30 13:27 UTC
From: flaimo at gmx dot net Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5CVS-2003-06-29 (dev) OS: win xp
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: flaimo at gmx dot net
New email:
PHP Version: OS:

 

 [2003-06-29 15:35 UTC] flaimo at gmx dot net
Description:
------------
the line "echo $cl->getComment(0)->message;" (see sourcecode) should show an error that i tried to access a private variable, but instead the script just stops working. without this line the script works fine.

Reproduce code:
---------------
http://pastebin.com/13998. (the linebreak in the comment is not in the original script!)

Expected result:
----------------
an error message

Actual result:
--------------
nothing

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-29 16:42 UTC] magnus@php.net
There is no code there.. Please provide a script to 
reproduce the problem. 
 [2003-06-29 16:43 UTC] magnus@php.net
status.. 
 [2003-06-29 17:01 UTC] flaimo at gmx dot net
hm, seems like they delete old post after a day or so...
i'll post it here:

-----------------------------------------

<?php
error_reporting(E_ALL & E_NOTICE);
class Comment {

	private $id;
	private $name;
	private $message;

	function __construct($id, $name, $message) {
		$this->id = $id;
		$this->name = $name;
		$this->message = $message;
    }

	function getID() {
		return $this->id;
	}

	function getName() {
		return $this->name;
	}

	function getMessage() {
		return $this->message;
	}
} // end Comment

class CommentList {

	private $list;

	function __construct() {
    }

    function addComment(Comment $comment) {
    	$this->list[] = $comment;
    }

    function getComment($id) {
    	return 	$this->list[$id];
    }

} // end CommentList


$mycomment = new Comment(1, 'Michael', 'Here is my message');
$cl = new CommentList();
$cl->addComment($mycomment);
echo $cl->getComment(0)->message; // why doesn't this line show an errormessage?
echo $cl->getComment(0)->getMessage();
?>
 [2003-06-30 13:27 UTC] sterling@php.net
This is the expected behaviour when you access a private member on a class that cannot be logically determined.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 09:01:38 2025 UTC