Skip to content

Commit

Permalink
Begin the crusade against references
Browse files Browse the repository at this point in the history
See smrealms#317.

In strict PHP, you can only assign variables by reference. Things
that are not variables include function calls and constants.

So we begin the herculean task of removing all unneeded references.
Here are some important details about references:

* Objects are always passed/copied by reference (in the c++ sense).
  We can pass an object without the `&` and still access/modify
  its internal data.

* Arrays are passed/copied by value, but not really because of
  copy-on-write, which means that it will only make a copy of
  the array if you try to modify it.

* References disable copy-on-write. If you have an array that was
  copied by value, and then you take a reference to it, you will
  immediately make a copy of it, even if the reference doesn't
  modify that array.

>>> Moral of the story <<<

Do not use references in an attempt to improve performance. PHP
does all the right performance things behind the scenes _if_
you are using the language in the intended way.

References are only intended for when you truly want to pass
something to another function and have that function modify it.

For more details, see
http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html
  • Loading branch information
hemberger committed Feb 23, 2018
1 parent 7242027 commit e15d502
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions templates/Default/engine/Default/includes/Missions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ if(isset($MissionMessage)) { ?>
echo $MissionMessage;
}

$AvailableMissions =& $ThisPlayer->getAvailableMissions();
$AvailableMissions = $ThisPlayer->getAvailableMissions();
if(count($AvailableMissions) > 0) {
foreach($AvailableMissions as $MissionID => &$AvailableMission) { ?>
foreach($AvailableMissions as $MissionID => $AvailableMission) { ?>
<span class="green">New Mission: </span><?php
echo bbifyMessage($AvailableMission['Steps'][0]['Text']); ?><br/><br/>
<div class="buttonA"><a href="<?php echo Globals::getAcceptMissionHREF($MissionID); ?>" class="buttonA">&nbsp;Accept&nbsp;</a></div><br/><?php
}
}


$Missions =& $ThisPlayer->getActiveMissions();
$Missions = $ThisPlayer->getActiveMissions();
if(count($Missions) > 0) {
foreach($Missions as $MissionID => &$Mission) {
foreach($Missions as $MissionID => $Mission) {
if(in_array($MissionID, $UnreadMissions)) { ?>
<span class="green">Task Complete: </span><?php
echo bbifyMessage($Mission['Task']['Text']); ?><br/><?php
Expand Down

0 comments on commit e15d502

Please sign in to comment.