Archive

Archive for the ‘PHP’ Category

PHP5 Tutorial – instanceOf Operator Explained

November 15th, 2007 2 comments

PHP5 introduces a new operator by the name of instanceOf. instanceOf is used to check if two objects passed as operands belong to the same class. This check can also happen when an object is compared with a class name.

In PHP4 a similar functionality existed with a method is_a(), which has been replaced by the instanceOf operator in PHP5.

Read more…

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

PHP5 Tutorial – $this variable explained

November 14th, 2007 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 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 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 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:

PHP Access Specifiers – Public, Private, Protected and Default with Examples

November 14th, 2007 31 comments

In the earlier tutorial we have witnessed keywords like public, private and protected. These are nothing but access specifiers. So, let’s understand what access specifiers viz. public, private, protected and default are with examples.

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 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:

PHP Class Constructor with Examples

November 14th, 2007 10 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 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 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: