Icon
Icon
Icon
Icon
Icon
Icon
12:37 AM
0 comments


Private Member Variables
Note:  Private Member Variables functionality may or may not be a part of the Zend
Engine 2.0.  Whether it is added to the engine or not will be publicly discussed.
Background
In the Zend Engine 1.0, all variables within objects are accessible to the outside world,
for both reading and writing.
Need
Often, objects hold information that may only be modified by methods of their class, in
order to maintain consistency and data protection.  In addition, in case Multiple
Inheritance is introduced to the Zend Engine 2.0, it will become much more important to
ensure that member variables from one parent class don’t clash with member variables
from another parent class, simply for having the same common name.
Overview
The Zend Engine 2.0 will introduce special notation for declaring variables as private. 
Private member variables will be accessible only to methods that belong to the class to
which they belong.  In case an attempt is made to access a private variable from outside
the scope of a valid class method, a fatal error will occur.  Due to the proposed
implementation, it will not be possible to reference private member variables indirectly
(i.e., by the use of $$varname notation), but only by using the variable name itself.
Functionality
Private member variables will be declared and manipulated in the following way:

class foo {
private $priv_var;
function some_method(…)
{
$priv_var = …;
}
};
$obj = new foo;
$obj->priv_var = …; // will result in a fatal error
Compatibility notes
No compatibility notes. Dependencies of feature
No dependencies.

If You Enjoyed This Post Please Take a Second To Share It.

You Might Also Like

Stay Connected With Free Updates

Subscribe via Email

teaser