douan4106 2016-02-16 11:09
浏览 32
已采纳

包括调用文件中无法访问的文件变量

Note: The variable is set in included file, the issue is not an undefined variable, hence the duplicate question is not relevant to my question. PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"

Edit: i just noted my localhost include path is set to C:\xampp\php\PEAR when i did echo get_include_path(); but i don't get error for included file not found rather the variable is undefined.

I have 2 files in C:/xampp/htdocs/test/ index.php config.php

Content of index.php:

require 'config.php';
echo $name;

Content of config.php:

$name = 'xyz';

And i get Notice: Undefined variable: name Where the $name = 'xyz' is in config.php which is included before using the variable.

I have to yet test it on live server. Please guide.

  • 写回答

2条回答 默认 最新

  • doo6568 2016-02-16 13:09
    关注

    Holly Cow.

    There was no error in the file. The php start tag was not correct, it was short tag <? ?> instead of <?php ?> this was causing the issue.

    i'm using php7 on my localhost. but of course t would work on older version of PHP and hosting.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services