PHP constructors & destructors

PHP constructors & destructors


Constructor methods for classes can be declared. Classes having a constructor method can call this method on each new object.

Void __ construct(arguments);

Class base
      Function __constrcutor()
            Print “In base class”;

Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required.


The destructor methods are called as soon as all references to a particular object are removed or when the object is explicitly destroyed.

Like constructors, parent destructors will not be called implicitly by the engine. In order to run a parent destructor, one would have to explicitly call parent::__destruct() in the destructor body.

Function __destruct()
PHP’s $_GET variable is used to collect names and data from a form using the method GET.
PHP server-side validation
Server side validations work when the client side validations fail to work ( if the java script is turned off).
PHP cookies
A cookie is used for identification purposes. It is more commonly used to identify a user in a session. It is a small file the application inserts on the users computer......
Post your comment