setcookie() function is using to set cookies in php
To declare Cookies syntax will be:- setcookie(name, value, expire, path, domain);
name : Name of the cookie
value : Value of the cookie
expire : The time for cookie to expire
path : path to save the cookie where we want … Read more
What is the use of var_dump in PHP ?
var_dump() function is used to display structured information(type and value) about one or more variable
syntax:- var_dump(variable1,variable2,variablen);
$a=5;
$b=5.1;
$c=true;
var_dump($a,$b,$c);
OUTPUT :
int(5) float(5.1) bool(true)… Read more
What is str_replace()
This function replace some characters with some other characters in a string , this function is case sensitive
syntax:- str_replace(find,replace,string);
find:-required,specifies the value to find
replace:-required,specifies the value to replace the value in find
string:-required,specifies the string to searched
echo str_replace(“world”,”india”,”hello world”);
OUTPUT :
hello india… Read more
What is Final Keyword in PHP ?
PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.
class BaseClass {
public function test() {
echo “BaseClass::test() called\n”;
}
final public
What is difference between abstract class and interface ?
An interface does not contain any code,it contain only declaration of methods,properties,events. Interfaces allow us to code which specifies which methods a class must have implement. Interfaces defines with the word interface. All methods in interfaces must be public.
interface SomeInterface
{
public function doSomething( $variable );
}
Abstract classes… Read more
The basics of a Class in PHP
Basic class definitions begin with the keyword class, followed by a class name, followed by a pair of curly braces which enclose the definitions of the properties and methods belonging to the class.
A class may contain its own constants, variables (called “properties”), and functions (called “methods”).
Properties of a PHP Class
Class member variables are called “properties”.They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration.In order to maintain backward compatibility with PHP 4, PHP 5 will still accept the use of the keyword var in property declarations instead of (or in … Read more
PHP Class Constants
It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that you don’t use the $ symbol to declare or use them.
class MyClass
{
const CONSTANT = ‘Kiran’;
function showConstant() {
echo self::CONSTANT . “\n”;
Autoloading Classes in PHP
Define an __autoload() function which is automatically called in case you are trying to use a class/interface which hasn’t been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.
PHP Constructors and Destructors
Constructors : PHP 5 allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.