php unexpected t_if,PHP,解析錯誤:語法錯誤,意外的T_IF,期望T_FUNCTION

Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in C:\wamp\www\Exam Creator\cls_FillInTheBlank.php on line 31

解析錯誤:語法錯誤,意外的T_IF,期望T_FUNCTION在C:\wamp\www\考試主創\cls_FillInTheBlank。php在31日行

I received this error while trying to run the cls_FillInTheBlank.php which includes cls_template.php. I have the two files posted at the for review.

我在嘗試運行cls_FillInTheBlank時收到了這個錯誤。php包括cls_template.php。我已經把這兩個文件貼在了審查處。

cls_FillInTheBlank.php

include("cls_template.php");

class fillintheblank{

function _construct(){

$cls_blankInput = new template;

$cls_questionString = new template;

$cls_fillInTheBlank = new template;

}

if(class_exists($cls_blankInput)){

$cls_blankInput->fillString("");

$cls_blankInput->fillPlaceholderStrings(array("[qInputName]","[qInputId]","[qInputValue]"));

} else {

print("\$cls_blankInput not defined.
");

}

if(class_exists($cls_questionString)){

$cls_questionString->fillString(""); // to be set later

$cls_questionString->fillPlaceholderStrings(array("[fib_blank]"));

} else {

print("\$cls_questionString not defined.
");

}

if(class_exists($cls_fillInTheBlank)){

$cls_fillInTheBlank->fillString("

[qFillInTheBlankString]");

$cls_fillInTheBlank->fillPlaceholderStrings(array("[qFillInTheBlankString]"));

} else {

print("\$cls_fillInTheBlank not defined.
");

}

public function q_fib_buildString($cls_question){

$i_qID = ""; // @type INTEGER

$s_html = ""; // @type STRING

$a_inputs = ""; // @type ARRAY

$s_innerHTML = ""; // @type STRING

$s_outerHTML = ""; // @type STRING

$i_qID = $cls_question->qo_i_id;

// build the HTML for the blank input

foreach($cls_question->qo_a_answerSet as $answer){

$this->cls_blankInput->fillPlaceholderValues(array("qID_".$i_qID,"qID_".$i_qID,$answer["value"]));

$a_inputs[count($a_inputs)] = $this->cls_blankInput->buildTemplate();

}

// build the inner HTML

$this->cls_questionString->fillString($cls_question->qo_s_string);

$this->cls_questionString->fillPlaceholderValues($a_inputs);

$s_innerHTML = $this->cls_blankInput->buildTemplate();

// build the outer HTML

$this->cls_fillInTheBlank->fillPlaceholderValues($s_innerHTML);

$outerHTML = $this->cls_fillInTheBlank->buildTemplate();

return $outerHTML;

}

public function q_fib_buildString($s_template){

$s_fib_patterns = array();

$s_input_blank = "";

$s_fib_patterns_blank = "[\[fib_blank\]]";

// array of placeholders

$a_fib_patterns['input'] = array();

// place holder for the name attribute of the input tag

$a_fib_patterns['attribute']['name'] ="[\[qInputName\]]";

// place holder for the id attribute of the input tag

$a_fib_patterns['attribute']['id'] = "[\[qInputId\]]";

// array of values

$a_fib_replace['value'] = array();

// value for the name attribute

$a_fib_replace['value']['name'] = "qId_".$i_id."[]";

// value fo the id attribute

$a_fib_replace['value']['id'] = "qId_".$i_id."[]";

// build blank input

$s_input_blank = preg_replace($a_fib_patterns['input'],$a_fib_replace['value'],fillintheblank::$s_blankInput);

// build question string

$s_string = preg_replace($s_fib_patterns_blank,$s_input_blank,$s_string);

/* START CODE FOR TESTING */

// echo($s_input_blank); // echo code for the blank inputs

/* END CODE FOR TESTING */

// return question string

return $s_string;

}

}

?>

2 个解决方案

#1

5

You've basically got this:

基本上你已經得到了這個:

class fillintheblank {

if (...) {

}

if (...) {

}

}

That's not permitted. A class definition has member variables and method definitions (ie: functions). You can't put "naked" PHP code in a class definition. YOu'll have to wrap it in a method, probably a constructor.

這是不允許的。類定義有成員變量和方法定義(即:函數)。您不能在類定義中放入“裸”PHP代碼。您將不得不將它封裝在一個方法中,可能是一個構造函數。

#2

0

Your problem is you started a class, but then you started writing what would usually be found in a function body in it. You need to enclose lines 27-56 in a function definition.

你的問題是你開始了一個類,然后你開始寫通常在函數體中找到的東西。您需要在函數定義中包含第27-56行。

Also, unrelatedly, you named a method _construct when you probably meant __construct. Two underscores, not just one.

而且,當您可能意味着__construct時,您會毫不猶豫地命名一個方法_construct。兩個下划線,而不是一個。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值