Archive

Archive for the ‘PHP’ Category

PHP5 Tutorial – $this variable explained

November 14th, 2007 admin 4 comments

$this variable is a pointer to the object making the function call. $this variable is not avialable in static methods. We will learn more about static methods in the next series of tutorials.

Read more…

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags:

PHP Script to Extract Email Address from any text

November 14th, 2007 admin 6 comments

I have developed a function that you can embed in your PHP applications that will help you extract email addresses from a given piece of text.

I have tested this on a string of (actually 4 – 5 paragraphs) text and this has performed very well.

Please feel free to use this code in your applications and let me know if you face any issues.

Read more…

Categories: PHP, PHP Code Examples, Programming Tags:

Stack Implementation in PHP5 – Stack Class

November 14th, 2007 admin 1 comment

Refer to the code below which is a PHP5 Stack Class – an implementation of Stacks. You are free to use it in your programs.

Read more…

Categories: PHP, PHP Class Examples, PHP Tutorials Tags:

PHP5 Tutorial – Function – Method Type Hinting in PHP5

November 14th, 2007 admin 1 comment

PHP5 Introduces Method Type Hinting. Type Hinting allows a function to force parameters to be objects of a particular class by specifying the name of the class in the function prototype.

Type Hinting is optional in all cases except catch block.

Read more…

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags:

PHP5 Tutorial OOPS – PHP5 Class Access Specifiers – public, private and protected

November 14th, 2007 admin 31 comments

In the earlier tutorials we have witnessed keywords like public, private and protected. These are nothing but access specifiers. So, lets understand what access specifiers are.

Definition of Access Specifiers
Access specifiers specify the level of access that the outside world (i.e. other class objects, external functions and global level code) have on the class methods and class data members. Access specifiers can either be public, private or protected.

Read more…

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags:

PHP5 Tutorial OOPS – Creating a PHP5 Destructor __destruct()

November 14th, 2007 admin 2 comments

Definition of a Destructor
A destructor is a special function of a class that is automatically executed whenever an object of a class is destroyed.

What does this all mean?
Let’s revisit that definition in more simple terms. A destructor is a special function – this means that a destructor is a function; but its special. But, why is it special? It’s special because it is automatically executed or called when an object of a class is destroyed. An object of a class is destroyed when

  1. it goes out of scope,
  2. when you specifically set it to null,
  3. when you unset it or when the program execution is over.

Read more…

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags:

PHP5 Tutorial – Creating a PHP5 Constructor __construct()

November 14th, 2007 admin 9 comments

Definition of a Constructor
A constructor is a special function of a class that is automatically executed whenever an object of a class gets instantiated.

What does this all mean?
Lets revisit that definition in more simple terms. A constructor is a special function – this means that a constructor is a function; but its special. But, why is it special? It’s special because it is automatically executed or called when an object of a class is created.

Read more…

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags:

PHP5 Tutorial – Defining Methods of a PHP5 Class

November 8th, 2007 admin 8 comments

In this PHP5 tutorial you will learn about methods and how to declare and use them in PHP5 class.

Definition of an class method
A class method/functions is the behavior/functionality of a class i.e. they provide the necessary code for the class in which it is defined. Examples could be a saveCustomer() method in the class Customer or a printDocument() in the Document class.

Methods act (perform operations) on the data members of the class and can be declared as private or public. A class method is exactly similar to PHP functions, it’s just that class functions are declared inside classes and accessed using the -> (arrow operator / dereferencing operator).

Read more…

PHP5 Tutorial – Defining Attributes of a PHP5 Class

November 8th, 2007 admin 8 comments

In this tutorial you will learn about class attributes and how to declare & use them in PHP5 classes.

Definition of an class attribute
An attribute is also know as data members and is used to hold data of a class. The data that it holds are specific to the nature of the class in which it has been defined. For example, a Customer class would hold data related to a customer, an Order class would hold data related a an order.

Read more…

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags:

PHP5 Tutorial – Learn to Create a PHP5 Class Object

November 8th, 2007 admin 1 comment

In the earlier PHP5 OOPS tutorial you learnt how to create a class in PHP5. In this tutorial you will learn how to create an object of a PHP5 class. But before we begin, lets understand what is an object.

Definition of an Object
An object is a living instance of a class. This means that an object is created from the definition of the class and is loaded in memory. A good analogy to understand this is to compare objects with humans – and understand that all of us (you and I) are objects. If God wants to send a human to earth, what is easy for Him to do? Create and define properties and attributes of each human separately or create a one time template and generate objects out if it. Therefore, this onetime template is a Class and you, I & everyone in this world is an object – that is a living instance of class Human.

Read more…

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags: