【问题标题】:Error: Only variables should be passed by reference error? [duplicate]错误:只有变量应该通过引用传递错误? [复制]
【发布时间】:2016-09-23 20:21:20
【问题描述】:

这是相关代码。其他人在堆栈溢出方面也遇到了类似的问题,但尝试了其中的几个解决方案,但在这种情况下似乎不起作用。似乎部分代码需要存储在一个变量中,然后将该变量存储在 $path 中。

$path = ltrim( end( @explode( get_template(), str_replace( '\\', '/', dirname( __FILE__ ) ) ) ), '/' );

这发生在 Ubuntu 的最新版本上。

【问题讨论】:

  • 你使用的是什么 PHP 版本,get_template 的输出是什么?
  • 我使用的是 PHP 7.0.8

标签: php


【解决方案1】:

答案取决于您使用的 PHP 版本,但候选是 END 函数。

无论如何,这段代码将永远有效:

$templatePath = str_replace( '\\', '/', dirname( __FILE__ ) );
$templatePathArray = @explode( get_template(), $templatePath );
$lastDir = end($templatePathArray);
$path = ltrim( $lastDir, '/' );

PS。你确定你在explode中使用了正确的分隔符吗?

【讨论】:

  • 感谢您回来,PHP 7.0.8。我会试试上面的!
  • 效果很好,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-08
  • 2016-10-11
  • 2017-07-08
相关资源
最近更新 更多