php call non static method from static method

Solutions on MaxInterview for php call non static method from static method by the best coders in the world

showing results for - "php call non static method from static method"
Agustina
31 Sep 2016
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
Alessio
10 Aug 2020
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?>
queries leading to this page
php call non static methodphp have a static and non static method with the same namephp call a no static function from a static methodstatic method phpphp method for call non static methodsget static function phprun non static method in static method phpphp error 3a non static methodphp access non static function in static functionphp how to call non static method from static methodnon static phpnon static method in a static method in phphow to call non static method php classnon static method phphow to make function non static in phpphp call non static method from stringhow to use non static variable in static method phpwhat is non static method in phphow to call a non static method as a static method phpphp call function by name non staticphp access non static functionphp static function calling a non static functioncall class non static methods in static function php 24this static function phpphp getstatic function by namestatic function phphow to call non static function in static function of php classadd property in staic method oop phpcall non static method inside static method phpphp call non static method inside it 27s own classcall a non static method from a static method phphow to call a non static function from a non static function in phpphp calling methods statical 3blyphp static and non static functionsphp call non static method inside staticphp call non static method staticallyhow to call non static method in another class in phphow to call non static method from static method of different class phpphp static methodsphp how to call a non static method inside a static methodhow to call non static method inside static method in phphow to call non static method phpstatic function call non static function phpaccess non static variable from static method phpphp call static function within classhow to call non static method from static method in phpnon static method inside static method phpcan we call static method from non static method phcall static method from non static method phpwhy avoid static methods phpphp static vs non static functionreference a non static function phphow to use static function to call non static function phpphp calling methods staticallyuse non static variable in static method phpaccess static properties inside static methods phpwhy would you want to use a static method over a non static phpnon static function in phpcall non static method in static method phpcall non static method phpnon static function phphow to call a non static method in a static function in phpcall non static method from static method phpnon static method inside static method phpphp mock static methodcall non static function from static function phpphp static methodphp cannot make non static methodphp call static method as non staticnon static method from static phpget property in static function phpcall non static method statically phpphp use static functionaccess non static method from static method phpcall a non static method from a static method in php laravelphp call non static method from static methodaccess non static method from static phpphp call non static method from static method