-1

我有一个 PHP 脚本的一部分,但它给出了 T_CLASS 错误。

但我不确定如何将 VAR 元素转换为符合 php5 的代码......有人可以帮助我吗?

<?php // Defining the "calc" class
if (!class_exists('calc'))
class calc {
var $number1;
}
?>

ps这只是更大代码的一部分,但它一直说:“PHP语法检查:解析错误:语法错误,第3行代码中出现意外的T_CLASS”。所以错误应该在“class calc {”或“var $number1;”中。请帮助:P

我不得不放置整个代码。只是添加括号给了我一个新的错误。

<?php // Defining the "calc" class
if (class_exists('calc')) {
class calc {
var $number1;
}
}
function boek($number1)
{
$result =$number1 * 2;
echo "Om een tekst van $number1 pagina's te redigeren, rekenen wij: <strong>€ $result,-*</strong></br>";
echo "<small>*Deze prijs is slechts een indicatie. Om een vrijblijvende offerte aan te vragen kunt u gebruikmaken van het contactformulier onderaan de pagina. <br/><span style=\"text-decoration: underline;\">Let op: studenten krijgen op vertoon van hun studentenpas 25% korting.</span></small>";
}
}
//Creating object of class
$calc = new calc();
?>
<style type="text/css">
.calcbutton {
Cursor: pointer;
    display: block;
    text-indent: -5000px;
    width: 136px;
    height: 44px;
    border: none;
    background-image: url('http://www.mijncreaties.com/wp-content/themes/GoedVerwoord/images/buttons.png');
    background-repeat: no-repeat;
}
.calcbutton {background-position: top left;}
.calcbutton:hover {background-position: center left;}
.calcbutton:active {background-position: bottom left;}
</style>
<form name="calc" action="" method="POST">
<table>
    <tr>
        <td>Aantal pagina's: </td>
        <td><input type="text" style="padding-left: 3px;" class="calc-form wpcf7-text" name="value1" value="0" onfocus="if (this.value == '0') {this.value = '';}" onblur="if (this.value == '') {this.value = '0';}"><br>
        <input type="hidden" name="oper" value="boek">
        </td>
    </tr>
</table>
<input type="submit" value="Bereken prijs" name="submit" class="calcbutton">
</form>
<?

if($_POST['submit']){
$number1 = $_POST['value1'];
$oper = $_POST['oper'];
if(!$number1){
echo "<p><font color=\"red\">Vul a.u.b. een getal in.</font></p>";
}
if($oper == "boek"){
$calc->boek($number1);
}
}
?>
4

2 回答 2

3

尝试将其包裹在一组额外的大括号中:

<?php // Defining the "calc" class

if (!class_exists('calc')) {
    class calc {
        var $number1;
    }
}

?>

编辑添加:

if (class_exists('calc')) {
class calc {
var $number1;

function boek($number1)
{
$result =$number1 * 2;
echo "Om een tekst van $number1 pagina's te redigeren, rekenen wij: <strong>€ $result,-*</strong></br>";
echo "<small>*Deze prijs is slechts een indicatie. Om een vrijblijvende offerte aan te vragen kunt u gebruikmaken van het contactformulier onderaan de pagina. <br/><span style=\"text-decoration: underline;\">Let op: studenten krijgen op vertoon van hun studentenpas 25% korting.</span></small>";
}
}
}

您的右括号在错误的位置。

于 2012-09-12T14:20:18.790 回答
2

用括号括起来if

<?php    
// Defining the "calc" class
if (!class_exists('calc')){
    class calc {    
        var $number1;    
    }
}    
?>

有条件地创建函数时,您将遇到同样的问题:

<?php    
if (!function_exists('new_function')){
    function new_function{    
       return 'awesome';   
    }
}    
?>
于 2012-09-12T14:20:52.390 回答