【发布时间】:2014-02-01 06:04:38
【问题描述】:
我是 PHP 新手,遇到错误:
"Fatal error: Cannot use object of type Confrence as array on line 22"
我正在尝试将放入数组中的数据放入表中,其中第 1 列第 1 行中有 1 号种子,第 2 列第 1 行中有 16 号种子。我不知道这是否正确这样做的逻辑,但这是我的目标。由于某种原因,它不会回显数组的第一个索引。这是我的代码。
Class Conference:
<?php
class Confrence
{
public $team1;
public $team2;
function loadGame($teamone, $teamtwo)
{
$this->$team1 = $teamone;
$this->$team2 = $teamtwo;
}
}
?>
This is my main code.
<?php print( '<?xml version = "1.0" encoding = "utf-8"?>' ) ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>User Selection Page</title>
</head>
<?php
require_once("loadGameClass") or die ("Could not load file");
$westTeams = array();
$loadGameClass = new Confrence();
$loadGameClass->loadGame("(1) Gonzaga", "(16) Southern U");
$westTeams = $loadGameClass;
echo $westTeams[0];
?>
<body>
</body>
</html>
【问题讨论】:
-
Confrence类是否实现了ArrayAccess? -
您的对象正在通过 loadGame() 设置 team1 和 team2,然后您将对象分配到数组变量中,这将永远无法通过在分配给数组变量之前将对象转换为 (数组) $loadGameClass;
-
你能打印出你想要的结果吗?
标签: php