php代码中的随机语法错误,我可以';找不到

php代码中的随机语法错误,我可以';找不到,php,Php,通常我不喜欢带着新手代码问题来到这里,但是没有人能找到这个代码的错误。也许你们可以:-) 获取照片; 错误是: 分析错误:语法错误,第15行的/home/p14s9nnd/public_html/testing.php中出现意外的“(”,应为“,”或“;” 先谢谢你,对不起 问候,, 马克斯 缺少结束括号?我认为在PHP中定义类成员时不能使用函数或变量 所以这里的这行是错误的: private $apiSig = md5($_sigString); 'api_key' => $apiKe

通常我不喜欢带着新手代码问题来到这里,但是没有人能找到这个代码的错误。也许你们可以:-)

获取照片;
错误是:

分析错误:语法错误,第15行的/home/p14s9nnd/public_html/testing.php中出现意外的“(”,应为“,”或“;”

先谢谢你,对不起

问候,, 马克斯


缺少结束括号?

我认为在PHP中定义类成员时不能使用函数或变量

所以这里的这行是错误的:

private $apiSig = md5($_sigString);
'api_key' => $apiKey,
'perms'  => $perms,
'api_sig' => $apiSig
private $authArrayImploded = implode('&', $authArray);
private $authLink = 'http://www.flickr.com/services/auth/?' . $authArrayImploded;
请看这里:

该声明可能包含一个初始化,但该初始化必须是一个常量值——也就是说,它必须能够在编译时进行计算,并且必须不依赖于运行时信息才能进行计算


声明类属性时不能使用函数/方法。这应该是导致错误的原因,但正如其他人所指出的,此代码存在一些问题,会阻止其执行。

Mike B对第一个解析错误给出了第一个正确答案,但这些行也不会起作用:

// this array declaration won't work because you can't reference variables
// ($apiKey, $perms, $apiSig) in a class declaration.
private $authArray = array('api_key' => $apiKey,
  'perms'  => $perms,
  'api_sig' => $apiSig);

// you can't call functions in class declaration
private $authArrayImploded = implode('&', $authArray);

// you can't use the '.' operator (or any other operator) here.
private $authLink = 'http://www.flickr.com/services/auth/?' . $authArrayImploded;

你应该在构造函数中初始化所有这些值。

我真希望我有足够的代表来编辑帖子。因为你的代码格式不好,我真的看不懂你的问题。顺便说一句,我不知道这是否是有意的,但你首先定义一个
$sigString
变量,然后在下一行中使用一个名为
$\u sigString
的变量说。真的吗?嗯,这看起来不友好,这会解释很多。谢谢。事实上,如果他们没有执行此规则,那么您的类变量默认值可能会意外更改,具体取决于类首次包含的时间。
private $apiSig = md5($_sigString);
'api_key' => $apiKey,
'perms'  => $perms,
'api_sig' => $apiSig
private $authArrayImploded = implode('&', $authArray);
private $authLink = 'http://www.flickr.com/services/auth/?' . $authArrayImploded;
private $apiSig = md5($_sigString);
// this array declaration won't work because you can't reference variables
// ($apiKey, $perms, $apiSig) in a class declaration.
private $authArray = array('api_key' => $apiKey,
  'perms'  => $perms,
  'api_sig' => $apiSig);

// you can't call functions in class declaration
private $authArrayImploded = implode('&', $authArray);

// you can't use the '.' operator (or any other operator) here.
private $authLink = 'http://www.flickr.com/services/auth/?' . $authArrayImploded;