php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #5142 Allow properties and methods of a class to be declared as public or private
Submitted: 2000-06-20 11:33 UTC Modified: 2002-04-27 13:34 UTC
From: juhl at eisenstein dot dk Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.0 Release OS: Linux
Private report: No CVE-ID: None
 [2000-06-20 11:33 UTC] juhl at eisenstein dot dk
This is just a simple feature request.

I would like to be able to define methods and properties of a class as either public or private (public could be the default if not specified, to maintain backwards compatibility with the current syntax).

Being able to declare methods/properties as private to a class makes a lot of sense if many people are sharing the same codebase and use classes they have not written themselves. If all properties and/or methods of a class are public, then people could possibly set a property or call a method that would cause the class to misbehave. I know this can be guarded against by programming the class "defensively", and also that people could just read the class definition to learn its proper use, but being able to just declare some parts of the class as private solves the above problems nicely and easily.

A syntax such as the following would make sense to me:

class myClass
{
	public {
		var $myPublicProperty;

		function myPublicMethod()
		{
		}
	}
	private {
		var $myPrivateProperty;

		function myPrivateMethod()
		{
		}
	}
}


Please consider this :-)

Best regards
Jesper Juhl
juhl@eisenstein.dk

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-27 13:34 UTC] jimw@php.net
implemented in ZE2.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 04:01:29 2024 UTC