Closed markkrueg closed 8 years ago
I'm trying to further debug this, as it caused my server to crash 13 times today alone.
If I am understanding the crash log; the problem is that a null value is being passed in line 59 of GeoLocation.php to the setServerGeoLocation public function.
Looking at this function, it is crashing here:
public function setServerGeoLocation(string $location){
I assume there is a problem using "string $location" when $location is null?
How would I avoid ever sending a null here?
public function onCompletion(Server $server){
/** @var Loader $plugin */
$plugin = $server->getPluginManager()->getPlugin("EssentialsPE");
if(!is_array($this->getResult())){
$plugin->getAPI()->setServerGeoLocation($this->getResult());
}else{
foreach($this->getResult() as $spl => $loc){
$plugin->getAPI()->updateGeoLocation($this->player[$spl], ($loc !== "server" ?? $plugin->getAPI()->getServerGeoLocation()));
}
}
Could I enclose this code section with a test for null?
Sorry, I'm not really much of a PHP coder...any help would be much appreciated.
The setter method needs to be updated to accept null. This can be done by adding = null
as default in the method declaration.
@iksaku
Thanks @PEMapModder So basically line 729 should look like:
[729] public function setServerGeoLocation(string $location = null){
I will experiment with this.
Pull request submitted. I have not seen a crash since this change.
Reference: This works because:
"The declaration can be made to accept NULL values if the default value of the parameter is set to NULL."
as written here:
@markkrueg Yes, thank you. Just waiting for @iksaku to merge it when he has finished his current commit.
I do have a fix for this locally, but allowing NULL would create a warning when "getting" the location, since that other function expects string to be returned... I will not merge it and I'll try to push the commit today
I am receiving this crash several times per day: