Skip to main content

Openings for different technoogies.

What is Constructor and Destructor?

 Constructor:

Constructor is a special type of function which will be called automatically whenever there is any object created from a class.

//Old (PHP4) class myClass{ function myClass(){ // Define logic in constructor } }
//New (PHP5+) class myClass{ function __construct(){ // Define logic in constructor } }
Note- Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.
Destructor:

Destructor is a special type of function which will be called automatically whenever any object is deleted or goes out of scope.

class myClass{ function __construct(){ // Define logic in constructor } function __destruct(){ // this is destructor } }
Types of constructors:
  1. Default constructor
  2. A constructor without any parameters is called a default constructor.

  3. Parameterized constructor
  4. A constructor with at least one parameter is called a parametrized constructor.

    class Person{ public $name; public $address; public function __construct($name){ // parameterized constructor with name argument $this->name = $name; } } $perObj1 = new Person("Full Stack Tutorials"); // parameterized constructor with name argument echo $perObj1->name; //Output: Full Stack Tutorials
  5. Copy Constructor
  6. class Person{ public $name; public $address; public function __construct($name){ // parameterized constructor with name argument $this->name = $name; } public function __clone(){ } } $perObj1 = new Person("Full Stack Tutorials"); // parameterized constructor with name argument $perObj2 = clone $perObj1; // copy constructor initialize $perObj2 with the values of $perObj1 echo $perObj2->name; //Output: Full Stack Tutorials
  7. Static Constructor
  8. Private Constructor
  9. Purpose of Private Constructor: It ensures that there can be only one instance of a Class and provides a global access point to that instance and this is common with The Singleton Pattern.

    class myClass { private static $instance; private function __construct() { } public static function get_instance() { if (!self::$instance) self::$instance = new myClass(); return self::$instance; } }

Comments

Popular posts from this blog

Openings for different technoogies.

 

PHP Interview questions 4

1) what is magic quotes? Ans :      Magic Quotes is a process that automagically escapes ncoming data to the PHP script. It’s preferred to code with magic quotes off and to instead escape the data at runtime, as needed. This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. 2) what is cross site scripting? SQL injection? Ans :      Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. Examples of such code include HTML code and client-side scripts. SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby

Looking for Drupal Themer

Location : Bangalore Position : Drupal Themer Job Responsibilities: • Work with Drupal Developer in porting pages to Drupal • Responsible for building Drupal themes and template files for themes for requirements specified Preferred profile: Strong Knowledge of Drupal coding standards. Strong grasp of semantic, HTML and CSS based design • Experience in converting PSDs and into functional Drupal themes from scratch • Experience in creating well-commented, Zen-based subthemes (http://drupal.org/project/zen) from provided layered Photoshop compositions, including creating and editing templates for different node-types and pages, editing .info files, and adding additional theme settings using the Drupal Form API. • Experience in adding, editing and deleting pages, users, user groups, blocks, and block areas on a pre-existing Drupal installation based on provided directions, text, pictures and wireframes • Experience in testing and modifying Drupal themes and stylesheets to ensure consistent