1. stdclass
2. magic methods
3.Class/Object Functions.
4.namespace
5. overloading
6. comparing objects
Monday, December 27, 2010
Saturday, December 25, 2010
Php tit bits
Configuring logging in php :
1. open php.ini file located under XAMPP/xampp/php/php.ini
2. set the following attributes
display_errors
Log_errors
error_log
Global key word:
The variable declared global will be accessible through out the entire php and also other php files that are included . it will also be accessible inside function provided they are resolved using the global keyword
Session variables not getting propagated ?
Add the following line of code in all phps
session_start();
Understanding $this :
The methods in a class can be invoked in two modes one by creating an instance for the class and invoking the method through that instance. The second way would be invoke the method in static mode with out creating an instance. $this represents the instance on which the method is invoked. similar to the "this" key word in java. The difference being as shown in the example below
Class A {
variable data = "class A";
method tellClass() {
echo data;
}
}
Class B {
variable data = "class B";
method callClassA () {
A:: tellClass()
}
}
objB = new ClassB();
objB-> callClassA();
Output :
ClassB
Static keyword
1 . static variable can be accessed without creating an instance using the scope resolution :: operator
2. non static variables cannot be accessed using the scope resolution operation they can onlybe accessed by creating instances
3. non static functions can be accessed using the scope resolution operator. though this is deprecated. will raise E_STRICT warning
4. $this cannot be used inside a static function to resolve other static /non static variables. use 'self' ex self::$bar. Note self can only be used to access static properties you will not be able to access non static properties using 'self' keyword
5. You will have to use $this or the self keyword to access class level properties directly using the variable name will not resolve to the class level property.
6. non static variables cannot be accessed inside a static function
7. you will not be able to access static properties using an instance of the class. Note: though this will not result in an error the value will be empty/null
8. you can call a static function using an instance of the class.
Access Specifiers in PHP :
public : methods/properties can be accessed from all the classes through an instance.
protected : methods/properties can be accessed within the same class and also all the inherited classes
private: methods/properties can be accessed only with the same class
String :
1. single quoted string does not print the values of the variable in them. It will also print special characters as they are .
ex $data = "CAT";
echo ' this is the $data';
ouput:
this is the $data
2. double quoted stings prints the values of the variables in them. they also interpret escape sequences.
3. heredoc - <<<"label" : this is similar to double quoted string except that it prints ' " ' without any need for escape sequence
4. nowdoc - <<<'label' : this is similar to single quoted string except that it prints "' " without a need for escape sequence.
1. open php.ini file located under XAMPP/xampp/php/php.ini
2. set the following attributes
display_errors
Log_errors
error_log
Global key word:
The variable declared global will be accessible through out the entire php and also other php files that are included . it will also be accessible inside function provided they are resolved using the global keyword
Session variables not getting propagated ?
Add the following line of code in all phps
session_start();
Understanding $this :
The methods in a class can be invoked in two modes one by creating an instance for the class and invoking the method through that instance. The second way would be invoke the method in static mode with out creating an instance. $this represents the instance on which the method is invoked. similar to the "this" key word in java. The difference being as shown in the example below
Class A {
variable data = "class A";
method tellClass() {
echo data;
}
}
Class B {
variable data = "class B";
method callClassA () {
A:: tellClass()
}
}
objB = new ClassB();
objB-> callClassA();
Output :
ClassB
Static keyword
1 . static variable can be accessed without creating an instance using the scope resolution :: operator
2. non static variables cannot be accessed using the scope resolution operation they can onlybe accessed by creating instances
3. non static functions can be accessed using the scope resolution operator. though this is deprecated. will raise E_STRICT warning
4. $this cannot be used inside a static function to resolve other static /non static variables. use 'self' ex self::$bar. Note self can only be used to access static properties you will not be able to access non static properties using 'self' keyword
5. You will have to use $this or the self keyword to access class level properties directly using the variable name will not resolve to the class level property.
6. non static variables cannot be accessed inside a static function
7. you will not be able to access static properties using an instance of the class. Note: though this will not result in an error the value will be empty/null
8. you can call a static function using an instance of the class.
Access Specifiers in PHP :
public : methods/properties can be accessed from all the classes through an instance.
protected : methods/properties can be accessed within the same class and also all the inherited classes
private: methods/properties can be accessed only with the same class
String :
1. single quoted string does not print the values of the variable in them. It will also print special characters as they are .
ex $data = "CAT";
echo ' this is the $data';
ouput:
this is the $data
2. double quoted stings prints the values of the variables in them. they also interpret escape sequences.
3. heredoc - <<<"label" : this is similar to double quoted string except that it prints ' " ' without any need for escape sequence
4. nowdoc - <<<'label' : this is similar to single quoted string except that it prints "' " without a need for escape sequence.
Subscribe to:
Posts (Atom)