PHP 8.1 preg_split() fails with depreciated error when no Static Authors are defined
Closed this issue · 2 comments
EEKimS commented
[Deprecated] preg_split(): Passing null to parameter #2 ($subject) of type string is deprecated
Line 709 in /var/www/sites/the-wise-hippo/vendor/silverstripe/blog/src/Model/BlogPost.php
I feel like this function needs something to check if the AuthorNames is null, something like this maybe:
if( !is_null($this->AuthorNames) ){
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames));
}else{
$authors = [];
}
michalkleiner commented
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames ?? ''));
should do it. Can you open a PR?
EEKimS commented
I have never done one of those, but i can say that digging around in the most recent branch looks like this issue has already been solved with the line:
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames ?? '') ?? []);
It appears that i need to force an update in my code. Thank you for your help!