1class Foo {
2
3 private $foo;
4 private $bar;
5
6 public function __construct($foo, $bar)
7 {
8 $this->foo = $foo;
9 $this->bar = $bar;
10 }
11
12 public function fun1()
13 {
14 return $this->foo . ' - ' . $this->bar;
15 }
16
17 public static function fun2($foo, $bar)
18 {
19 return (new self($foo, $bar))->fun1();
20 }
21}
22
23echo Foo::fun2('foo', 'bar');
24
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?>