duandi6531 2014-05-27 23:31
浏览 17
已采纳

PHP共享数据

I'm working on a small project, and I was hit with a brick wall today; one that I surprisingly couldn't find an answer to.

So heres my setup,

  config.php => loads 'user.php' and 'project.php'
  user.php => class script loaded into 'config.php'
  project.php => class script loaded into 'config.php'
  main.php => uses 'config.php' to access 'user.php' and 'project.php'

Now, to clarify my problem, I want 'user.php' to be able to access 'project.php' through 'config.php'.

config.php

require_once( 'connect.php' );
require_once( 'user.php' );
require_once( 'project.php' );

// ...

user.php

Project::function(...);

// ...

I want 'user.php' to be able to access 'config.php' to access variables and other classes, and I know 'require_once' only let's config inherit from the specified file, but I'm wondering if there's a workaround that lets both access eachother.

Any suggestions? User and Project are in two entirely separate directories for specific reasoning.

  • 写回答

1条回答 默认 最新

  • douzhong6480 2014-05-27 23:34
    关注

    In your config.php, include project.php prior to including user.php. This should give user.php access to everything in project.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥15 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)