Thread View: mailing.www.php-dev
2 messages
2 total messages
Started by alavoor
Fri, 29 Jun 2001 23:45
All PHP programmers: Follow code convention for pvt, prt and pub declaratiosn
Author: alavoor
Date: Fri, 29 Jun 2001 23:45
Date: Fri, 29 Jun 2001 23:45
58 lines
3933 bytes
3933 bytes
Hello:
I follow this code convention and I recommend that all the PHP
programmers follow the same to remain consistent.
PHP scripting language provides object oriented features through the
class keyword. Features like public, private and protected will be
supported in the future release (they
are in TODO list). In the meantime, you can use the following coding
conventions to distinguish between private, public and protected
variables:
1.All private variables and functions always start with underscore
"_" followed by lowercase letters like var $_myvar;
2.All Protected variables and functions always start with "_T"
followed by lowercase letters like var $_Tmyvar;
3.All Public variables and functions do not start with underscore "_"
like var $myvar;
4.All variables and functions always start with lowercase letter (no
uppercase) like var $_myvar; and NOT like var $_Myvar;
A sample class below:-
class someabc {
var $_conn; // Private variable
var $_Tmyvar; // Protected variable
var $connMYCONNECTION; // Public variable
var $connToDb; // Public variable
var $myvar3; // Public variable
var $myvarTHISTEST; // Public variable
function _foofunction() {} // Private function
function _Tfoofunction() {} // Protected function
function foofunction() {} // Public function
}
The private, protected declarations provide the encapsulation and
data-hiding. But you must consider the following disadvantages of
encapsulation:
1. Encapsulation usually requires more code, hence it sacrifices
performance especially for scripting languages like PHP
2. Encapsulation requires lots of Set/Get methods for
private/protected properties.
3. Since encapsulation unneccessarily increases the code size, it is
not recommended for scripting language like PHP.
4. You can enforce a good degree of encapsulation by using the
coding convention suggested above.
See also my PHP-HOWTO doc at http://www.aldev.8m.com mirror
http://aldev0.webjump.com
Re: All PHP programmers: Follow code convention for pvt, prt and pub declaratiosn
Author: jason
Date: Mon, 02 Jul 2001 08:47
Date: Mon, 02 Jul 2001 08:47
14 lines
1940 bytes
1940 bytes
I don't get this part, which I list below. In part 2 you say to start the variable with an upper case letter, then in part 4 you say this should never be done. Which is it? Is "variables" a seperate class, like private, protected, and public? I thought all variables were public by default? > 2.All Protected variables and functions always start with "_T" > followed by lowercase letters like var $_Tmyvar; > 4.All variables and functions always start with lowercase letter (no > uppercase) like var $_myvar; and NOT like var $_Myvar
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads