[英]Random syntactical error in my php code that I can't find
Ordinarily I hate coming here with newbie code questions but nobody can find the error with this code. 通常,我讨厌在这里遇到新手代码问题,但是没人能找到与此代码相关的错误。 Maybe you guys can :-) 也许你们可以:-)
<?php
defined('SYSPATH') or die('No direct script access.');
/**
* to interact with photos
*
* @author Max Padraig Wolfgang Bucknell-Leahy
*/
class Model_Photos
{
private $apiKey = '12664498208a1380fe49fb1b5a238ef0';
private $secret = '03d43dee65a34513';
private $perms = 'read';
private $sigString = 'test';
private $apiSig = md5($_sigString); //Line 15
private $authArray = array('api_key' => $apiKey,
'perms' => $perms,
'api_sig' => $apiSig);
private $authArrayImploded = implode('&', $authArray);
private $authLink = 'http://www.flickr.com/services/auth/?' . $authArrayImploded;
public function get_photos($number = 5)
{
if(file_exists(APPPATH . 'cache/main_cache.xml')
{
echo $authLink;
} else {
echo 'not so good';
}
}
}
$class = new Model_Photos;
$class->get_photos;
the error is: 错误是:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/p14s9nnd/public_html/testing.php on line 15 解析错误:语法错误,第15行的/home/p14s9nnd/public_html/testing.php中出现意外的'(',期望为','或';'
Thank you in advance and sorry 预先谢谢你,抱歉
Regards, Max 此致Max
private $apiSig = md5($_sigString);
You can't use functions/methods when declaring class properties. 声明类属性时,不能使用函数/方法。 This should be the cause of your error but as others are pointing out, there are several issues with this code that will keep it from executing. 这应该是导致错误的原因,但是正如其他人所指出的那样,此代码存在一些问题,导致其无法执行。
if(file_exists(APPPATH . 'cache/main_cache.xml')
缺少右括号?
I don't think you can use functions or variables when defining class members in PHP. 我认为在PHP中定义类成员时不能使用函数或变量。
So this lines here are wrong: 所以这行是错误的:
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;
Have a look here: http://ch.php.net/manual/en/language.oop5.properties.php 在这里看看: http : //ch.php.net/manual/en/language.oop5.properties.php
This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated. 该声明可以包括一个初始化,但是此初始化必须是一个常量值-也就是说,它必须能够在编译时进行评估,并且必须不依赖于运行时信息才能进行评估。
Mike B has the first correct answer for the first parse error, but these lines aren't going to work either: 对于第一个解析错误,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;
You should be initializing all these values in the constructor. 您应该在构造函数中初始化所有这些值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.