Call non static method from static method php
I am working on PHP code. Show Here is the sample code to explain my problem:
How can I call the non-static method from the static method ?
asked Jan 13, 2017 at 9:46
RahulRahul 17.9k7 gold badges40 silver badges58 bronze badges 6 You must create a new object inside the static method to access non-static methods inside that class:
The result would be Later edit: As seen an interest in passing variables to the constructor I will post an updated version of the class:
The result would be answered Jan 13, 2017 at 9:51
Mihai MateiMihai Matei 23.8k5 gold badges33 silver badges50 bronze badges 3 The main difference would be that you can call static methods for a class without having to instantiate an object of that class. So, in your static method try
But I don't see how this would make any sense in any context. answered Jan 13, 2017 at 9:56
1
PHP 8.0 no longer allows to call non-static class methods with the static call operator ( Calling non-static methods statically raised a PHP deprecation notice in all PHP 7 versions, and raised a Strict Standards notice in PHP 5 versions.
In PHP 8.0 and later, this results in a fatal error:
This change is implemented throughout the engine. Variable Functions
CallablesPHP no longer considers an array with class name and a method (
This affects all functions ranging from
|