English 中文(简体)
PHP: 守则是否像这种可能性一样?
原标题:PHP: Is code like this possible?
  • 时间:2011-08-09 06:24:52
  •  标签:
  • php
  • class

我试图有一个用户界定的游戏地图清单。 由于我不知道设计时有多少地图将出现在阵列中,因此我试图动态地创造新的变量,以控制这些地图。 这是否可行? 我的失败尝试:

<?php
$maplist=array("map1.aamap.xml","map2.aamap.xml"); //edit this list with your maps
$rounds = 3;                 //times to play each map
/*======No need to edit below========*/
global $last;  //store the last played map               
class Map
{
    public $difficulty;
    public $played;  //amount of times played
}
foreach($maplist as $i => $element)
{
    $element = $map[$i];
    $map[$i] = new Map();
}
//snipped other code here
$map[$i]->$played = $x++;  //increment the times played counter <-- FAILS HERE
?>

Parser指出:Fatal差错: 不得获取空闲财产

这样做是否可行?

最佳回答

您的法典中有一些错误:

<?php
$maplist=array("map1.aamap.xml","map2.aamap.xml"); //edit this list with your maps
$rounds = 3;                 //times to play each map
/*======No need to edit below========*/
global $last;  //store the last played map               

既然你在此具有全球范围,而不属于职能范围,就不需要<条码>全球

class Map
{
    public $difficulty;
    public $played;  //amount of times played
}
foreach($maplist as $i => $element)
{
    $element = $map[$i];

这里是否有任何法典缺失? 您不使用<条码>代号,因此不需要这一转让。

    $map[$i] = new Map();
}
//snipped other code here
$map[$i]->$played = $x++;  //increment the times played counter <-- FAILS HERE

进入成员变量的星号为:$object->variable,而不是$object->$variable。 后者将评价<代码>可变,并将该数值作为变量名称(例如,如果$variable = “foo”,这将试图查阅$object->foo

使用<代码> 地图[$i]->meted =x++;代替。

问题回答

When accessing the properties of a class, you don t want to use the $ in front of the property name itself.

http://www.o.un.org。 致命错误: 不能从空置财产错误中获取。

如果你希望:

public function __get($name)
{
...
}

public function __set($name, $value)
{
...
}

members/a>

在这些职能中,你可以将数据储存在某些内部阵列结构中。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签