Things got a little bit messy when trying to use a library I made. This is what my project looks like without the unnecessary content.
lib_vars.php
<?php $lib_var = 10;?>
lib.php
<?php
    require_once('lib_vars.php');
    function lib_func(){
        global $lib_var;
        echo $lib_var;
    }
?>
action.php
<?php
    require_once('lib/lib.php');
    function action(){
        lib_func();
    }
?>
index.php
<?php
    require_once('action.php');
    function main(){
        if(true)
            action();
    }
    main();
?>
For some reason I have to place require_once('action.php') on top of index.php.
If I place it in the if-statement, It can't find $lib_var any more. If I have 10 different actions in index.php, than I would be forced to include 9 unnecessary files. Does someone know an alternative?
Thanks.
 
     
    