The following is directed to the PHP development team. I would like to suggest a capability be added to PHP's class implementation. Specifically, provide the capability to segregate class data and methods into private methods and data from those that are available for direct invocation from the object declaration. This would provide functionality similar to C++. Private methods and data may be accessed ONLY by the methods in the class definition. I would envision implementation to look something like one of these options:
OPTION A ============== declare private data and methods first class MyClass { var varA; var varB; var varC; function func1() { } function func2() { } public: var varX; var varY; var varZ; function funcM() { $this->varA = $this->func2(); $this->varX = $this->funcN(); return $this->varA; } function funcN() { } } OPTION B =============== declare public methods and data first class MyClass {: var varX; var varY; var varZ; function funcM() { $this->varA = $this->func2(); $this->varX = $this->funcN(); return $this->varA; } function funcN() { } private: var varA; var varB; var varC; function func1() { } function func2() { } } OPTION C ============= declare private methods and data with "private" keyword class MyClass { private var varA; private var varB; private var varC; private function func1() { } private function func2() { } var varX; var varY; var varZ; function funcM() { $this->varA = $this->func2(); $this->varX = $this->funcN(); return $this->varA; } function funcN() { } } In each of the above, data varX, varY, varZ and methods funcM() and funcN() could be invoked directly by the object. Data varA, varB, varC and methods func1() and func2() could not. Example: $example = new MyClass; $example->varX = 10; $example->varY = $b + $example->varX; $example->funcM(); $example->varZ = $example->varX + $example->funcN(); $q = $example->varA; // illegal - varA is private $example->func1(); // illegal - method func1() is private $example->varX = $example->varY + $example->varA; // illegal - varA is private FYI: some day, I'll ask for method overload. but that awaits another day. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php