Skip to content
Advertisement

Accessing private function in included php file [closed]

I currently have two php class files and I’m working on accessing functions across them. Currently, in the secondClass.php file, I’m able to call a function in firstClass.php successfully and that class then calls another in the same firstClass.php file which is expected to return a result

I can access the function successfully, but when I check if the firstClass function isLoaded is true or access it I get an error because it’s a private function

How can I get the returned object from this private function in firstClass.php?

firstClass.php

JavaScript

secondClass.php

JavaScript

Advertisement

Answer

You could add a property to the first class that is public.

JavaScript

Then you could change that value using your method. And I think technically your method name there is flirting with being a verb vs being a noun. You could update the existing isLoaded method to be something like checkIsLoaded which sets the public property to true or false.

JavaScript

Now you can access it with the same format you have:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement