Showing posts with label PHP Basics. Show all posts
Showing posts with label PHP Basics. Show all posts

Saturday, March 30, 2013

PHP Basic -> Performance

Please put your doubts in below comments

PHP Basic -> Config


  1. How to install php?
  2. What are the default configuration likemax_file_uploads, max_execution_time, memory_limit, upload_max_filesize and upload_tmp_dir etc
  3. From where to change the default configuration.? 
  4. How to install new plugin/module in PHP?
  5. Why we need to compile after installation new plugin?
  6. Why we use ini_set and what we can do with this?


Following things keep in mind regarding this topic(Minimum)

  • Default configuration of PHP varaibles.
  • What is apache
  • What is zend engine
  • PEAR
  • Apache Environment
  • HTTP Headers Information
  • Core modules
  • New featurs in PHP5.3
  • Deprecated function in PHP5.3

PHP Basic -> Extensions

PHP supports to install external plugin/modules that can fullfil your required requirement. For install any plugin/module to need to do the following things


  • Put all files in exertions directory.
  • link then files in php.ini
  • Restart the aapache. 

Following things keep in mind regarding this topic(Minimum)
  • How to install new extension in PHP
  • How to un-install old extension in PHP
  • What is Use of CURL

PHP Basics -> Namespaces

While Preparing for Examination, you must be able to reply following questions.

  1. What is namespaces in PHP?
  2. What is difference between namespace operator (namespace) and namespace constant(__NAMESPACE__).
  3. What are the significance of namespaces?
  4. Which version of PHP support namespaces?
  5. How to use a function that belongs to some namespaces.


If you have any doubt then let me know?

Sunday, March 24, 2013

PHP Basic -> Control Structures


Control Structures: These are those things which control how the program "flows". Control are very important for any language whether it is PHP OR C.

  • if
  • else
  • elseif/else if
  • while
  • do-while
  • for
  • foreach
  • break
  • continue
  • switch
  • declare
  • return
  • require
  • include
  • require_once
  • include_once
  • include
  • include_once
  • goto
I hope you are aware of above all.



Following are the property of Control constructs.
  • Parenthesis are optional means include "class.php" or include ("class.php") both work.
  • these are faster as compare to Normal function like strstr, array_merge etc. 

Following things keep in mind regarding this topic(Minimum)
  • Difference between include, include_once, require and require_once
  • Deprecated control structessuppress the error 
  • What is use of declare
  • Difference between continue and break
  • Why use return in functions of PHP. 



PHP Basic -> Constant

Constant: constant means which is not going to change. Mainly we use constant  to declare a variable which is not going to change. for example to see the config file path.

You can define a constant by using the define()-function or by using the const keyword outside a class definition as of PHP 5.3.0.

Following are the way to set and get the constant value.
/** set the constant**/
define('CONFIG_FILE_PATH','/config');
/** set the constant**/

/** get the constant**/
echo CONFIG_FILE_PATH;
/** get the constant**/

Above CONFIG_FILE_PATH is constant, it is available in throughout the page. but it cannot be re-declare.



Following things keep in mind regarding this topic(Minimum)
  • PHP constants Array
  • PHP constants Class
  • Use of define, constant etc
  • How to check a variable defined or not
  • How to check a constant is exist of not


PHP Basic -> Variables

What is variable?
Variable are the container of information. Variable can store many type of  information like string, number, array, object etc.


Following are the rules for PHP variables:

  •     A variable starts with the $ sign, followed by the name of the variable
  •     A variable name must begin with a letter(A-Z) or the underscore character(_)
  •     A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  •     A variable name should not contain spaces
  •     Variable names are case sensitive ($a and $A are two different variable)

Following are the example of different type of variables
/** Variable store number**/
$a=10;
$b=12;
var_dump($a);
var_dump($b);
/** Variable store number**/

/** Variable store string**/
$name='Arun';
var_dump($name);
/** Variable store string**/

     
/** Variable store array**/
$dataTypes = array('Int','String','Array','Object');
var_dump($dataTypes);
/** Variable store array**/

/** Variable store Object**/
class ABC{
}
$obj = new ABC();
var_dump($obj);     
 /** Variable store Object**/


Following things keep in mind regarding this topic(Minimum)

  • Whar are PHP Variables and their use. 
  • What are different types of variable like Array, Object and String etc
  • Manipulation of varaibles
  • Global, Static, local variables and their scope 
  • Dynamic varaibles
  • Session variables and server variables
  • Manipulation of variables.









Saturday, March 23, 2013

PHP Basic -> Operators

Following are the different type of operators in PHP.

  1.    Operator Precedence
  2.     Arithmetic Operators
  3.     Assignment Operators
  4.     Bitwise Operators
  5.     Comparison Operators
  6.     Error Control Operators
  7.     Execution Operators
  8.     Incrementing/Decrementing Operators
  9.     Logical Operators
  10.     String Operators
  11.     Array Operators
  12.     Type Operators


Operator Precedence: When we use multiple operator in one statement, operator run according to the priority. Following are the table of operator precedence which we must keep in mind while doing any calculation in PHP OR running multiple operator in one statement. we can also change the operator priority by using the bracket "()".

Operator Precedence

Associativity Operators Additional Information
non-associative clone new clone and new
left [ array()
right ++ -- ~ (int) (float) (string) (array) (object) (bool) @ types and increment/decrement
non-associative instanceof types
right ! logical operator
left * / % arithmetic operator
left + - . arithmetic and string
left << >> bitwise operator
non-associative < <= > >= comparison operator
non-associative == != === !== <> comparison operator
left & bitwise and references operator
left ^ bitwise operator
left | bitwise operator
left && logical operator
left || logical operator
left ? : ternary operator
right = += -= *= /= .= %= &= |= ^= <<= >>= => assignment operator
left and logical operator
left xor logical operator
left or logical operator
left , many uses

Arithmetic Operators:These are those operator which we mostly use in calculation like plus, minus, divide, multiple, concat and change operator, modulus (+,-,/, x, .,-,%). In PHP to multiple two number  or more number we use "*"  instead of "x";
Operators Name of operators Detail Example Output
a + b Addition Sum of a and b 2 + 2 4
a - b Subtraction Difference of a and b 5 - 2 3
a * b Multiply Product of a and b 5 * 2 10
a / b Divide Quotient of a and b 15 / 5 3
a % b Modulus Remainder of a divided by b 5 % 2
10 % 8
10 % 2
1
2
0
- a Oppisite Opposite of a - 2
a . b Concatenation Concatenate two strings "php" . "certification" php certification


Assignment Operators: Assignment operator are used to assign the values to a variable.for example $a=10; Here 10 are assign to  a variable (i.e $a). In Following example, Example1 and Example2 works same as the doing method is different.
Example1 Example2 Operator
x = y x = y The left operand gets set to the value of the expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
a .= b a = a . b Concatenate two strings


Bitwise Operators:Bitwise operator are used to do the manipulate the according to their operators. Bitwise operator work on number.

Example Name Result
$a & $b And Bits that are set in both $a and $b are set.
$a | $b Or (inclusive or) Bits that are set in either $a or $b are set.
$a ^ $b Xor (exclusive or) Bits that are set in $a or $b but not both are set.
~ $a Not Bits that are set in $a are not set, and vice versa.
$a << $b Shift left Shift the bits of $a $b steps to the left (each step means "multiply by two")
$a >> $b Shift right Shift the bits of $a $b steps to the right (each step means "divide by two")


Comparison Operators: Comparison Operator are used to compare two variable having some values. when we are comparing two values they mostly return true or false. For Example 10<15 will return true as 10 is less then 15. Following table describe more.
Operator Name of Operator Example
a == b Equal 5==8 returns false
a === b Identical 5==="5" returns false
a != b Not equal 5!=8 returns true
a<>b Not equal 5<>8 returns true
a !== b Not identical 5!=="5" returns true
a>b Greater than 5>8 returns false
a<b Less than 5<8 returns true
a>= b Greater than OR equal to 5>=8 returns false
a<= b Less than OR equal to 5<=8 returns true


Error Control Operators: "@" is known as error control. As if we use this operator then error will not be generator for that statement. See is example below.
$a=10;
echo @$aa;


when we run able code, we are expecting the "$aa" should be generate error, but is not because we have use @ operator in front of $aa.

Increment / Decrement Operator: When we use this operator, variable value is increased in increment and value is decreased in
Operator Name Description
++$a Pre-increment Increments$a by one, then returns $a
$a++ Post-increment Returns $a, then increments $a by one
--$a Pre-decrement Decrements$a by one, then returns $a
$a-- Post-decrement Returns $a, then decrements $a by one
$a+=2 Post-increment Returns $a, then incremet $a by two
$a+=3 Post-increment Returns $a, then increment $a by three
$a-=2 Post-decrement Returns $a, then decrements $a by two


Logical Operator: Logical Operator are used to compare the two string/number.

Example Name Result
$a and $b And TRUE if both $a and $b are TRUE.
$a or $b Or TRUE if either $a or $b is TRUE.
$a xor $b Xor TRUE if either $a or $b is TRUE, but not both.
! $a Not TRUE if $a is not TRUE.
$a && $b And TRUE if both $a and $b are TRUE.
$a || $b Or TRUE if either $a or $b is TRUE.


String Operators: The operator which work on only on string. For Example "." and ".=" is known as string operator. 1st used to concat two or more strings. 2nd is work same but return the values.
for more detail read above.

Array Operators: The Operator which work for array known as array operator. Array operator are very useful while you are developing any website. Most of developer are unware of this. instead of using these function they created a function which work like this.
Means If you know about these operator, it will save your time and also minimize the code.

Example Name Result
$a + $b Union Union of $a and $b.
$a == $b Equality TRUE if $a and $b have the same key/value pairs.
$a === $b Identity TRUE if $a and $b have the same key/value pairs in the same order and of the same types.
$a != $b Inequality TRUE if $a is not equal to $b.
$a <> $b Inequality TRUE if $a is not equal to $b.
$a !== $b Non-identity TRUE if $a is not identical to $b.

Type Operator: "instanceOf" is type of operator which is used to check whether object is belong to that class or not. See below example.
"var_dump" return output alongwith their data type.

/** create TestClass **/
class TestClass{
function name(){
  return 'Im Good';
}             
}
/** create TestClass **/
$a = new TestClass;
     
/** create TestClass1 **/     
class TestClass1
{
}
/** create TestClass1 **/
var_dump($a instanceof TestClass);
var_dump($a instanceof TestClass1);


Execution Operator: "`" is known as execution operator. Backticks(``) is a operator which is used to execute the code.


Following things keep in mind regarding this topic(Minimum)
  • What are different types of operator
  • Operator Precedence and their associations. 
  • Difference between bitwise operator, logical operator and arithmetic operators.
  • How backets changes the precedence of operators

Friday, March 22, 2013

PHP Basics -> Syntax

How to Start PHP?
PHP is one of the famous server side language used to created dynamic web pages. For quick start install wampserver OR xampp server.

PHP Syntax
PHP Start with "<?php" and end with "?>"


PHP Single Line Comments
Following line will not print the statement i.e "Hello World" to the browser.
//echo "Hello World";


PHP Multiple Line Comments
/*
for($i=1; $i<=10; $i++){
echo "{$i}";
}*/


Following things keep in mind regarding this topic(Minimum)

  • How to declare  Array, String and Object variable.
  • How to access and  "add element" in array  object variable and manupulation on string variables.
  • How to write function syntax and use user defined functions.
  • Loop like For, While and Do while.
  • Closing of PHP tag is not compulsory in one line php code.
  • Single line, Multiple line comments
  •  What are the PHP different type of error like syntax error, warning, notice and user defined error etc.
  • Difference between single quoted comments and double quoted comments
  • How to store php value in variable instead of send the output to the browser.
  • How to parse variable in single quoted string and double quoted string.
  • PHP coding conventions like there must be spaces after and before of equal (=)