doudu8291 2015-10-28 16:01
浏览 27

从父文件运行PHP函数

I need some help for a problem i'm facing. I've look on the web but i only found more usual issues which cannot solve mine.

The main idea is to run PHP functions like get_included_files(), get_defined_vars(), debug_backtrace() from the parent file.

In my code i have a PHP file, let's call it A.php which is including another PHP file, let's say B.php. I would like to run for exemple get_included_files() into B.php to get the files included in A.php.

Something similar to parent:: but for PHP files and not oriented object programming. I'm aware that it could be a security flaw, that's why i'm not sure it is possible, but i ask to be sure.

To be the clearest possible, here is an example :

A.php

include 'B.php';
include 'C.php';
include 'D.php';

get_includes();

B.php

function get_includes()
{
    $included_files = get_included_files();
    print_r($included_files);
}

And i need the $included_files var to contain array('B','C','D'). My problem is the PHP functions getting the included files from the file it's launched in, not from the parent (with this code, the $included_files is empty).

  • 写回答

3条回答 默认 最新

  • doushi5913 2015-10-28 16:06
    关注

    Consider the example:

    a.php

    function a(){
        echo "a";
    }
    
    function b(){
        echo "b";
    }
    

    b.php

    include "a.php";
    
    echo a();//echoes a
    
    echo b();//echoes b
    
    评论

报告相同问题?

悬赏问题

  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow