|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 08:00:01 2025 UTC |
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(); ?>