email info@codeaffairs.com
Code Affairs Web Technologies!

widgets Call non static method like static in Php


Lets make an example to see how we can call non static php methods like static method. But not forgot it’s not a static method.

(new ClassName())->methodName();

Example:

echo 'Start..';

class testClass {
    public function testFunction() {
        return 'Test Value';
    }
}


 $testVar = new testClass();
 $testOutput = $testVar->testFunction();

// Output 1
 echo $testOutput;

// Output 2
 echo (new testClass())->testFunction();

Output 1 and Output 2 given same result.

bubble_chart Short Description

None
history_toggle_off Created: April 2, 2019, 9 a.m.

category Related Categories

visibility Total Read: 36