1<?php
2class Car
3{
4 public function test($var = 'Hello kinjal')
5 {
6 $this->var = $var;
7 return $this->var;
8 }
9}
10class Bike
11{
12 public static function test($var)
13 {
14 $var = '<br>this is static function';
15 return $var;
16 }
17}
18$obj = new Car();
19echo $obj->test();
20echo Bike::test('this is non static'); //static function called using :: double colon
21
22?>
1 <?php
2class ClassName {
3 public static function staticMethod() {
4 echo "Hello World!";
5 }
6}
7?>
1
2<?php
3function foo(){
4 static $int = 0; // correct
5 static $int = 1+2; // correct
6 static $int = sqrt(121); // wrong (as it is a function)
7
8 $int++;
9 echo $int;
10}
11?>
12
13
1<?php
2 class Toys
3 {
4 private $toys_name;
5 public $toys_category;
6 public static $shop_name;
7
8 function Toys($name,$category)
9 {
10 $this->toys_name = $name;
11 $this->toys_category = $category;
12 }
13
14 public function getToyName()
15 {
16 return $this->toys_name;
17 }
18
19 public function getToyCategory()
20 {
21 return $this->toys_category;
22 }
23
24 public function getToyShop_nonStatic()
25 {
26 return self::getToyShop();
27 }
28
29 public static function getToyShop()
30 {
31 return self::$shop_name;
32 }
33
34 public static function setToyShop($shopname)
35 {
36 self::$shop_name=$shopname;
37 }
38
39 }
40
41 $objToys = new Toys("Battery Car","Battery Toys");
42 $toys_name = $objToys->getToyName();
43 $toys_category = $objToys->getToyCategory();
44 echo "<br/>Toy: " . $toys_name . ", Category: " . $toys_category;
45
46 Toys::$shop_name = "Disney";
47 $shop_name = Toys::getToyShop();
48 echo "<br/>Shop Name: " . $shop_name;
49
50 Toys::setToyShop("ToyShop");
51 $shopname = Toys::getToyShop_nonStatic();
52 echo "<br/>Shop Name via non static function: " . $shopname;
53
54?>