Php意外T_String在php4的webhost,但不是在php5的localhost


Php unexpected T_String on php4 webhost but not on php5 localhost

我得到一个非常令人沮丧的问题与我的php脚本下面。使用XAMPP,在我的本地机器上一切正常,但是当我把它放到web上时,我得到:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/38/d220091779/htdocs/roughgiraffed/RG2/portfolio_item_vars.php on line 20

如果有人能帮我看一眼,或者给我一些建议,我将不胜感激。

错误在array_push($projectImages, $filePath);正下方靠近函数底部的那一行。

编辑:即使错误被列为在第20行(在getImages())我删除了下面的类,错误消失了。当然,我还是希望这门课能成功……但这是否意味着这是我的PHP版本的问题呢?

<?php
$pageTitle = "Portfolio";
//return an array of the (non-featured, non-thumb) images within a given project
function getImages($category, $project){
    $projectImages = Array();
    if ($dir = opendir("portfolio/" . $category . "/" . $project . "/")){
        //open each 'file' in the directory
        while($file = readdir($dir)){
            $filePath = "portfolio/" . $category.'/'.$project.'/'.$file;
            //check if it really is a file
            if($file != "." && $file != ".." && $file[0] != '.' && is_file($filePath)) {
                //check if it is an image
                if(getimagesize($filePath)){
                    //ignore featured_image and _thumbs
                    if(!strstr($file, "featured_image") && !strstr($file, "_thumb")){
                        //Add the non-featured, non-thumb image to the array
                        array_push($projectImages, $filePath);
                    }
                }
            }
        }
        closedir($dir);   
    }
    return $projectImages;
}
class ImgResizer {
    private $originalFile = '';
    public function __construct($originalFile = '') {
        $this -> originalFile = $originalFile;
    }
    public function resize($newWidth, $targetFile) {
        if (empty($newWidth) || empty($targetFile)) {
            return false;
        }
        $src = imagecreatefromjpeg($this -> originalFile);
        list($width, $height) = getimagesize($this -> originalFile);
        $newHeight = ($height / $width) * $newWidth;
        $tmp = imagecreatetruecolor($newWidth, $newHeight);
        imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
        if (file_exists($targetFile)) {
            unlink($targetFile);
        }
        imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 – 100 for output image quality with 100 being the most luxurious
    }
}
?>

我的主机正在运行PHP版本5.3.1

WebHost正在运行PHP Version 4.4.9

如果您使用PHP5特定的东西,例如PHP5引入的public关键字,则可能会在PHP4中发生这种奇怪的解析错误。

当你计划在PHP4和PHP5下运行相同的源代码时,你可能应该看看官方的PHP5向后不兼容列表。

摘录:

向后不兼容的更改

尽管大多数现有的PHP 4代码不需要修改就可以工作,但是您可以使用它应注意以下向后不兼容的更改:

  • 有一些新的保留关键字。
  • strripos()和strripos()现在使用整个字符串作为针。
  • 非法使用字符串偏移导致E_ERROR而不是E_WARNING。

:

在PHP 4中不能使用__construct()

必须使用与类名同名的函数。

用ImgResizer()代替__construct(),或者换一个更好的虚拟主机。

感谢评论中的帮助,我确定这实际上是php版本的问题。但是,我不知道为什么它在第20行给出错误,大约比违规代码高出十行。