0

Python has a function where we can execute a other python file and get methods from that file in vars. Below is the sample rough code to explain:=

file1.py
def method1():
   print 'hello world'

file2.py    
globals = file1.__dict__
execfile(file1.py, globals, locals);
# locals['method1'] has method up from file1.py. One can even execute it by doing locals['method1']();

I want similar method in PHP, where I can read other PHP file and get methods in a variable. Is this even possible

Umakant Patil
  • 2,227
  • 6
  • 32
  • 58
  • This is a bit against the idea of php, which simply is different from python. I doubt this is possible directly, though one probably could fake something somehow. But I do not see a straight solution for that. – arkascha Sep 26 '15 at 16:10
  • It's more or less what [`include`](http://php.net/include) does, apart from not offering distinct scopes. – mario Sep 26 '15 at 16:19

1 Answers1

0

You can define class in source PHP organized in namespace

eg:

source code vendor\vendorname\helpers.php

    <?php
    namespace vendor\vendorname\helpers;

    class TestHelper
    {
        public static function yourClassFunc ($param)
        {
            /** your code **/  

        }
    }

and use where you need simply declarinng

other php source (eg atest.hp)

use vendor\dfenx\helpers\UIHelper;
 ...........
echo UIHelper::yourClassFunc( $param);
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107