Skip to content

Precautions

Muqsit Rayyan edited this page Jul 10, 2020 · 3 revisions

At the current stage, there are some cases where PreProcessor will convert your very valid syntax to an invalid syntax.

The Obvious

  • Avoid using Preprocessor::export($output_folder, $overwrite = true) ($overwrite is false by default).
  • Read the output logged by PreProcessor to be aware of what changed.

PreProcessor::commentOut()

Method calls on the method results in syntax error

- $player->getUniqueId()->toString();
+ /* $player->getUniqueId() */->toString();

PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR)

Method calls that were encapsed in string result in unexpected behaviour

- $player->sendMessage("{$player->getName()} says Hello!");
+ $player->sendMessage("{{/* $player->getName() */}} says Hello!");

PHP Notice: Undefined property: Player::$getName
The string gets resolved to {{/* () */}} says Hello!

Method calls being assigned to a variable results in syntax error

- $x = $player->getUniqueId();
+ $x = /* $player->getUniqueId() */;

PHP Parse error: syntax error, unexpected ';'

Method calls returning a value results in error

function getId(Player $player) : UUID{
-	return $player->getUniqueId();
+	return /*$player->getUniqueId()*/;
}

PHP Fatal error: A function with return type must return a value

TIPS

  • Only comment out methods that do not return a value (i.e : void).
  • Do not assign variables in the method's argument list that you are commenting out.
  • Be sure the code you're commenting out will not alter the behaviour of the program. For example, do not do this if you are commenting out Logger::debug():
Logger::debug("Player joined with UUID: {$player->assignUUIDAndReturnIt()}");