Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP functions What are Functions? A function structure:

Similar presentations


Presentation on theme: "PHP functions What are Functions? A function structure:

1 PHP functions What are Functions? A function structure:

2 Eg For Globals

3 Eg For Statics

4 Conditional Functions

5 Nested Functions Here lname() can only be called after calling fname()

6 Function Arguments Passing By Value Eg:

7 Passing By Reference

8 Use Of Default Parameters Ex:

9 Continued

10 Variable Length Argument List and Variable Functions =2) print("the second arg is ".func_get_arg(1)." \n"); print("the no of arguments passed to this function are $numargs"); echo" "; $arg_list=func_get_args();

11 Continued for($i=0;$i<$numargs;$i++) { echo "Argument $i is: ". $arg_list[$i]. " \n"; } $c=$a+$b; return $c; } $d='add'; $e=$d(2,10); echo " sum=$e "; ?>

12 CLASSES A class is a collection of variables and functions which work on this variables. A simple class declaration: Class first{ //member variables public $a = 1; //method declaration public function display() { echo this->a;//member methods; }

13 New New is used to create an instance of a class, a new object must be created and assigned to a variable. a; } $b = new name; $b->display(); ?>

14 Extends and Constructors name; }

15 Continued class childclass extends parentclass { function display() { echo "Extending company\n"; parent::display(); } $extended = new childclass(); $extended->display(); ?>

16 Final It 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. Ex:

17 Visibility Private Protected public

18 Ex For Visibility public;

19 continued //$ob->protected; //$ob->private; //$ob->privateone(); class secondone extends firstone { public function hello() { $this->protected; $this->protectedone(); } $c=new secondone; $c->hello(); ?>

20 Scope Resolution Operator(::)

21 Abstract Classes getname(). "\n"; }

22 Continued class fname1 extends name { public function getname() { return "Relyon"; } public function prefixname($prefix) { return "$prefix"; } $class1 = new fname1; $class1->display(); echo $class1->prefixname('softech')."\n"; ?>


Download ppt "PHP functions What are Functions? A function structure:

Similar presentations


Ads by Google