LAMP Interview Questions
Collection of Linux, Apache, Mysql and Php Interview Questions
Saturday, August 31, 2013
How to write a constructor in php4 & in php5 ?
In PHP4, a constructor is a method with a name same as that of class itself. In PHP5, all constructors are named as __construct()
Thursday, August 1, 2013
Write a Regular expression to validate a url in php
if (preg_match('/^(http|https)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $url)) {
echo "Your url is ok.";
} else {
echo "Wrong url.";
}
echo "Your url is ok.";
} else {
echo "Wrong url.";
}
Sunday, May 5, 2013
In php5, If a class has both __construct() and class name as function, which will be called while creating objects ?
Answer: Only __construct() will be called.
Try out example
Try out example
<?php class myClass { function myClass() { echo "In class name"; } function __construct() { echo "In __construct"; } } $obj = new myClass(); ?>Output: In __construct
Subscribe to:
Posts (Atom)