我有一个PHP脚本的一部分,但是它给出了一个T_CLASS错误。
但我不确定如何将VAR元素转换为符合php5的代码...... 有人可以帮帮我吗?
<?php // Defining the "calc" class
if (!class_exists('calc'))
class calc {
var $number1;
}
?>
P.S。这只是更大代码的一部分,但它一直说:“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);
}
}
?>
答案 0 :(得分: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>";
}
}
}
你的结束括号错误。
答案 1 :(得分: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';
}
}
?>