2010-05-23 61 views
2

通常我讨厌用新手代码问题来到这里,但没有人可以用此代码找到错误。也许你们可以:-)在我的php代码中出现随机语法错误,我无法找到

<?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; 

的错误是:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/p14s9nnd/public_html/testing.php on line 15

预先感谢您和遗憾

问候, 最大

+0

我很希望我有足够的代表编辑帖子。我真的无法阅读你的问题,因为你格式不好的代码。 – Felix 2010-05-23 23:00:28

+1

顺便说一句,我不知道这是否是有意的,但你首先定义一个'$ sigString'变量,并在下一行使用一个叫'$ _sigString'。只是说。 – Javier 2010-05-23 23:00:55

回答

2
if(file_exists(APPPATH . 'cache/main_cache.xml') 

缺少一个右括号?

1

我不认为你可以在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; 

看看这里: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.

+0

真的吗?嗯,这似乎不友好,这将解释很多。谢谢 – maxbucknell 2010-05-23 23:04:14

+0

实际上,如果他们没有执行这个规则,那么你的类变量默认值可能会意外地改变,这取决于何时该类首次被包含。 – 2010-05-23 23:07:36

4
private $apiSig = md5($_sigString); 

声明类属性时,不能使用函数/方法。这应该是你的错误的原因,但正如其他人指出的,这个代码有几个问题会阻止它执行。

0

迈克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; 

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

相关问题