Skip Navigation LinksHome > Categories > Code from a Category

How to write classes in PHP



User Name: serfcompany
Name: Serf
Contact Me: www.datawebcoder.com
Home Page: www.datawebcoder.com
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 681
Add Date: 03/17/2012
This article is about the fact that represent a class written in PHP, how to write better in order to improve performance, and what common mistakes should be avoided, that would not give up on opportunities as their own, and in the possibilities of PHP in general.

In my understanding, the class - this is the same as the object, in any case, PHP is a word synonymous.
So, the class - a few variables and functions combined in one structure responsible for specific action or transaction.
An example is the class for defining a search query, the class of the navigation menu, in a word set of functions and variables that will be very convenient to combine under one "roof".
That is, creating a variable of a class, you can easily access any variables or functions inside the class.


An example of a simple PHP class that shows how to construct php-class and how they work:



In programming classes in PHP5 there are many new, for example, now you can "protect" the functions and variables by simply adding them to the "protected", "private" or "public".


protected - protects a variable or a function of changes outside of the class or his heirs. That is, it can only be changed within a class and its descendants.


private - provides access to an item class only within the class in which the element is declared. , This is very useful if you are using proprietary code (Zen Optimizer or something like that), for example, to check the activation code, shareware php-script.


public - Allows access to variable or function by any known methods and techniques.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.