嘿,我的代码中一直有语法错误,但我看到绝对没有错,也许第二组眼睛会有所帮助。
<?php
namespace SyzerPHP\Environment;
/**
* Config.
*/
class Config extends Environment
{
/**
* validate().
*
* Validate the config array.
*
* @param array $conf The config array.
*
* @throws DomainException If `$conf` argument is empty.
* @throws DomainException If `$conf` argument does not have a depth of 2.
* @throws UnexpectedValueException If a section is not the start of an array.
* @throws UnexpectedValueException If the section variable names are not capital letters.
* @throws LengthException If the section variable name and/or value is too long.
*
* @return void.
*/
public static function validate(array $conf): void
{
if (\empty($conf)) {
throw new Exception\DomainException('The config array is empty.');
}
if (\depth($conf) != 2) {
throw new Exception\DomainException(\sprintf(
'The config array does not have a depth of 2. Depth: `%s`.',
(string) \depth($conf)
));
}
foreach ($conf as $var => $val) {
if (!\is_array($val)) {
throw new Exception\UnexpectedValueException(\sprintf(
'The section is not the start of an array. Passed: `%s`.',
\e($var)
));
}
foreach ($val as $var2 => $val2) {
if (!\ctype_upper(\str_replace('_', '', $var2))) {
throw new Exception\UnexpectedValueException(\sprintf(
'The section variable name must all be caps. Passed: `%s`.',
\e($var2)
));
}
if (\strlen($var2) > 30 || \strlen($val2) > 250) {
throw new Exception\LengthException(sprintf(
'The `$var2` and/or `$val2` variable is too long. Passed: `$var2` = `%s` `$val2` = `%s`.',
(string) \strlen($var2),
(string) \strlen($val2)
));
}
}
}
self::clearConfig();
self::$conf = $conf;
}
}
堆栈跟踪指向此行if (\empty($conf)) {
。我发现代码没有错误。 php引擎期待一个标识符。就我而言,我缺少括号,括号或任何其他符号。函数开头的\
是为了防止替换攻击。另请注意,这是php 7.2
语法。如果我错过了一个错误,那么任何帮助都会很棒。提前谢谢。
答案 0 :(得分:1)
您应该删除反斜杠:
基本上,您正在呼叫的每个功能。
这些是PHP原生函数。使用\something
表示您试图指向某个命名空间。