ID:               26325
 User updated by:  drm at melp dot nl
 Reported By:      drm at melp dot nl
 Status:           Open
 Bug Type:         Zend Engine 2 problem
 Operating System: Windows XP
 PHP Version:      5.0.0b2 (beta2)
 New Comment:

J > Sorry i reacted that way, I misinterpreted your post. 

I cannot reproduce what you mean in PHP4. Can you give an example?

I tried some stuff, but all the versions i tried gave expected results.
Changing "private $member" into "var $member" or removing that line
completely results in:

-----
Member contains: Test constructor, though getMember() says: Test
constructor?
Member contains: a, though getMember() says: a?
-----

which is logical, since the member will be public as soon as you
introduce it, both with "var $member" and removing the line completely
(and initializing it in the Test constructor). When removing the
initialization in the Test constructor, the same notice as in the other
codesample will be produced. (Notice: Undefined property: member in
....)

btw: i figure this hasn't got anything to do with the fact that I
tested on WinXP, maybe that should be changed to OS: irrelevant?


Previous Comments:
------------------------------------------------------------------------

[2003-11-24 11:28:58] [EMAIL PROTECTED]

Take your original example and edit it so it works in PHP 
4. It runs in both 4 and 5 without a notice. Based on your 
original example code, that isn't "just plain bs."  
 
Upon further inspection based on your second example, 
there is definitely something weird going on here. This is 
most likely related to #26182. 
 
J 
 
I'm not positive, but I think this may have something to 
do with #26182.  
 
J 

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

[2003-11-22 18:57:46] drm at melp dot nl

You are right, i hadn't researched the problem that well, since i
assumed php5 would treat properties the php4-style the same way as php4
itself. But you are right; the code sample above when ran in php5
doesn't give a notice, though php4 does.

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

[2003-11-22 10:26:03] [EMAIL PROTECTED]

Actually, the main issue here is that PHP doesn't give a notice at all
if you access an undefined property, whether it is a private property
in a base class or not.



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

[2003-11-22 09:05:03] drm at melp dot nl

Excuse me, but you are *totally* missing my point here. You are telling
me things i had already pointed out in the first post.

I'll reduce my feature request to one simple line:

Can *at least* a "notice" be triggered when a private member variable
does not exist but is accessed? And by accessed i do NOT mean
assigned!

You're saying it behaves the same way php4 does, but that's just plain
bs. See the following code in PHP4:

<?
error_reporting ( E_ALL );
class Test {
   function getMember () {
      return $this->member;
   }
}
$t = new Test ();
echo $t->getMember ();
?>

This would yield the following notice:
Notice: Undefined property: member in test.php on line 5

All i'm asking is that some notice of the SAME sort can be implemented
in php5 when trying to access parent private members.

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

[2003-11-20 11:46:55] [EMAIL PROTECTED]

There are two issues here. 
 
First, PHP 5 is just acting like PHP 4 did -- you can 
initialize a member of an object without explicitly 
declaring it in the class definition and PHP won't 
complain. 
 
Second, Test::$member and DeriveTest::$member aren't the 
same things. Test::$member being private, it's only 
accessible and visible from within Test. DeriveTest has no 
idea it exists, so it creates its own public member called 
$member. If you do a print_r($o) at the end of your 
script, you'll see that there are two members called 
$member, one of which is private and the other public. 
 
So yes, this is intended behaviour. One of the main ideas 
of private members is that they aren't even visible from 
derived classes. If you try to access a private member 
from a parent class, the derived class won't see it and 
will instead try using its own member, and if that doesn't 
exist it will implicitly create it. 
 
J 

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/26325

-- 
Edit this bug report at http://bugs.php.net/?id=26325&edit=1

Reply via email to