Jump to content

Recommended Posts

Hey guys!

So I have some trouble with this fatal error:

Cannot access empty property

 

And the line of error is:

$returntime = $units->$y['endtime']-time();

More of the code if it's not enough:

$DefenderUnit = array();
$DefenderUnit = $database->getUnit($data['to']);
$evasion = $database->getVillageField($data['to'],"evasion");
$maxevasion = $database->getUserField($DefenderID,"maxevasion",0);
$gold = $database->getUserField($DefenderID,"gold",0);
$playerunit = ($targettribe-1)*10;
$cannotsend = 0;
$movements = $database->getMovement("34",$data['to'],1);
for ($y = 0; $y < count($movements); $y++) {
$returntime = $units->$y['endtime']-time();
if ($units->$y['sort_type'] == 4 && $units->$y['from'] != 0 && $returntime <= 10) {
$cannotsend = 1;
}
}
if ($evasion == 1 && $maxevasion > 0 && $gold > 1 && $cannotsend == 0 && $dataarray[$data_num]['attack_type'] > 2) {
$totaltroops = 0;
for ($i = 1; $i <= 10; $i++) {
$playerunit += $i;
$data['u'.$i] = $DefenderUnit['u'.$playerunit];
$database->modifyUnit($data['to'],array($playerunit),array($DefenderUnit['u'.$playerunit]),array(0));
$playerunit -= $i;
$totaltroops += $data['u'.$i];
}
$data['u11'] = $DefenderUnit['hero'];
$totaltroops += $data['u11'];
if ($totaltroops > 0) {
$database->modifyUnit($data['to'],array("hero"),array($DefenderUnit['hero']),array(0));
$attackid = $database->addAttack($data['to'],$data['u1'],$data['u2'],$data['u3'],$data['u4'],$data['u5'],$data['u6'],$data['u7'],$data['u8'],$data['u9'],$data['u10'],$data['u11'],4,0,0,0,0,0,0,0,0,0,0,0);
$database->addMovement(4,0,$data['to'],$attackid,microtime(true),microtime(true)+(180/EVASION_SPEED));
$newgold = $gold-2;
$newmaxevasion = $maxevasion-1;
$database->updateUserField($DefenderID, "gold", $newgold, 1);
$database->updateUserField($DefenderID, "maxevasion", $newmaxevasion, 1);
}
}

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/305425-cannot-access-empty-property-error/
Share on other sites

$units->$y['endtime']
That has one of two meanings, depending on your version of PHP, but neither of which are what you want:

1. Take $units, find a property named according to the value of $y, then treat it as an array and get its 'endtime' value.

2. Take $y, treat it as an array and gets its 'endtime' value, then use that value as the name of a property in the $units object.

 

In other words, writing "$y" makes it a variable and not a name of a property. Drop the $.

$units->y['endtime']
  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.