processwire / processwire-issues

ProcessWire issue reports.
45 stars 2 forks source link

PHP 8.4 Deprecations #2000

Closed BernhardBaumrock closed 1 day ago

BernhardBaumrock commented 6 days ago
Deprecated: ProcessWire\InputfieldHasSelectableOptions::addOption(): Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Interfaces.php on line 761
Deprecated: ProcessWire\Wire::isHooked(): Implicitly marking parameter $instance as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Wire.php on line 629
Deprecated: ProcessWire\WireHooks::isHooked(): Implicitly marking parameter $instance as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/WireHooks.php on line 337
Deprecated: ProcessWire\wireInstance(): Implicitly marking parameter $wire as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Functions.php on line 45
Deprecated: ProcessWire\Modules::hasPermission(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Modules.php on line 749
Deprecated: ProcessWire\Modules::hasPermission(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Modules.php on line 749
Deprecated: ProcessWire\Modules::___getModuleConfigInputfields(): Implicitly marking parameter $form as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Modules.php on line 1743
Deprecated: ProcessWire\WireSaveableItems::initItem(): Implicitly marking parameter $items as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/WireSaveableItems.php on line 250
Deprecated: ProcessWire\WireSaveableItems::log(): Implicitly marking parameter $item as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/WireSaveableItems.php on line 756
Deprecated: ProcessWire\WireSaveableItemsLookup::initItem(): Implicitly marking parameter $items as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/WireSaveableItemsLookup.php on line 112
Deprecated: ProcessWire\Fields::initItem(): Implicitly marking parameter $items as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Fields.php on line 253
Deprecated: ProcessWire\Fields::_hasPermission(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Fields.php on line 1250
Deprecated: ProcessWire\Fields::_hasPermission(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Fields.php on line 1250
Deprecated: ProcessWire\Fieldgroups::isFieldNotRemoveable(): Implicitly marking parameter $template as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Fieldgroups.php on line 601
Deprecated: ProcessWire\Pages::___clone(): Implicitly marking parameter $parent as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Pages.php on line 1047
Deprecated: ProcessWire\Pages::uncacheAll(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Pages.php on line 1695
Deprecated: ProcessWire\PagesLoaderCache::uncacheAll(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PagesLoaderCache.php on line 170
Deprecated: ProcessWire\PagesEditor::_clone(): Implicitly marking parameter $parent as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PagesEditor.php on line 1305
Deprecated: ProcessWire\Field::___viewable(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Field.php on line 882
Deprecated: ProcessWire\Field::___viewable(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Field.php on line 882
Deprecated: ProcessWire\Field::___editable(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Field.php on line 901
Deprecated: ProcessWire\Field::___editable(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Field.php on line 901
Deprecated: ProcessWire\Page::__construct(): Implicitly marking parameter $tpl as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Page.php on line 611
Deprecated: ProcessWire\Page::next(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Page.php on line 2198
Deprecated: ProcessWire\Page::nextUntil(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Page.php on line 2255
Deprecated: ProcessWire\Page::prev(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Page.php on line 2279
Deprecated: ProcessWire\Page::prevUntil(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Page.php on line 2318
Deprecated: ProcessWire\PageTraversal::nextSibling(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PageTraversal.php on line 1154
Deprecated: ProcessWire\PageTraversal::prevSibling(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PageTraversal.php on line 1198
Deprecated: ProcessWire\PageTraversal::nextAllSiblings(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PageTraversal.php on line 1229
Deprecated: ProcessWire\PageTraversal::prevAllSiblings(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PageTraversal.php on line 1263
Deprecated: ProcessWire\PageTraversal::nextUntilSiblings(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PageTraversal.php on line 1294
Deprecated: ProcessWire\PageTraversal::prevUntilSiblings(): Implicitly marking parameter $siblings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PageTraversal.php on line 1346
Deprecated: ProcessWire\Permission::__construct(): Implicitly marking parameter $tpl as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Permission.php on line 53
Deprecated: ProcessWire\Role::__construct(): Implicitly marking parameter $tpl as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Role.php on line 31
Deprecated: ProcessWire\User::__construct(): Implicitly marking parameter $tpl as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/User.php on line 47
Deprecated: ProcessWire\User::___hasPagePermission(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/User.php on line 241
Deprecated: ProcessWire\User::getPermissions(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/User.php on line 411
Deprecated: ProcessWire\Session::sessionHandler(): Implicitly marking parameter $sessionHandler as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Session.php on line 1709
Deprecated: ProcessWire\PageFinder::getPageArrayData(): Implicitly marking parameter $pageArray as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/PageFinder.php on line 3665
Deprecated: ProcessWire\Inputfield::getAttributesString(): Implicitly marking parameter $attributes as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Inputfield.php on line 1377
Deprecated: ProcessWire\Inputfield::renderReady(): Implicitly marking parameter $parent as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Inputfield.php on line 1471
Deprecated: ProcessWire\Inputfield::___renderReadyHook(): Implicitly marking parameter $parent as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/Inputfield.php on line 1492
Deprecated: ProcessWire\InputfieldWrapper::importArray(): Implicitly marking parameter $inputfields as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/InputfieldWrapper.php on line 1980
Deprecated: ProcessWire\ModulesConfigs::getModuleConfigInputfields(): Implicitly marking parameter $form as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/ModulesConfigs.php on line 561
Deprecated: ProcessWire\ModulesLoader::hasPermission(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/ModulesLoader.php on line 750
Deprecated: ProcessWire\ModulesLoader::hasPermission(): Implicitly marking parameter $page as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wire/core/ModulesLoader.php on line 750
Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /var/www/html/wire/core/Session.php on line 287
Warning: session_name(): Session name cannot be changed after headers have already been sent in /var/www/html/wire/core/Session.php on line 291
Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /var/www/html/wire/core/Session.php on line 297
Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /var/www/html/wire/core/Session.php on line 298
Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /var/www/html/wire/core/Session.php on line 299
Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /var/www/html/wire/core/Session.php on line 300
adrianbj commented 5 days ago

@ryancramerdesign - as a quick initial followup - PW won't even load in PHP8.4 at the moment because of those session errors at the end of the OP above. As a quick hack to get things going so I can start testing, I commented out these lines:

        if($this->config->https && $this->config->sessionCookieSecure) {
            ini_set('session.cookie_secure', 1); // #1264
            if($this->config->sessionNameSecure) {
                session_name($this->config->sessionNameSecure);
            } else {
                session_name($this->config->sessionName . 's');
            }
        } else {
            session_name($this->config->sessionName);
        }

Once logged in, I could re-enable them.

The "Implicitly marking parameter $sessionHandler as nullable" is easily fixed by adding a ? mark, eg:

public function sessionHandler(?WireSessionHandler $sessionHandler = null) {

https://dev.to/gromnan/fix-php-84-deprecation-implicitly-marking-parameter-as-nullable-is-deprecated-the-explicit-nullable-type-must-be-used-instead-5gp3

adrianbj commented 5 days ago

Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in wire/core/Sanitizer.php:4506

adrianbj commented 5 days ago

Deprecated: ProcessWire\SelectableOptionManager::updateLanguages(): Implicitly marking parameter $event as nullable is deprecated, the explicit nullable type must be used instead in Fieldtype/FieldtypeOptions/SelectableOptionManager.php on line 785

There are going to be a LOT of these nullable errors popping up so note that in some cases you might want to define multiple types, like string|array|null rather than one type with the preceding ?

adrianbj commented 5 days ago

Sorry to spam, but just wanted to note that I've updated Tracy to deal with the most obvious of its 8.4 deprecation errors - it had lots that were making things a mess and in one case causing a cannot modify header information error.

adrianbj commented 5 days ago

More implicit null errors:

Database.php on line 142
MarkupFieldtype.php on line 82
MarkupQA.php on line 74
MarkupQA.php on line 620
Pagefile.php on line 428
Pageimage.php on line 1790
adrianbj commented 4 days ago

Just a reminder that the ? prefix for type declarations isn't available until PHP 7.1 and union/multiple types aren't available until 8.0, so you might need an alternate approach or change the requirements listed here: https://processwire.com/docs/start/install/new/

ryancramerdesign commented 2 days ago

@adrianbj @BernhardBaumrock

There are a lot of cases where an argument needs to allow any type of value, and the function determines the action based on the type. The nullable "?" option requires a specific declared type, and PHP won't accept "mixed?" as the type because it says "mixed already includes null". Naming all types (PHP8) isn't always possible. And PHP also won't accept function foo(?$val = null), so I seem to be stuck. Maybe I'll just focus on the instances where "?" can be used, and then later revisit the instances where it can't. For the moment though, it seems we'd have to suggest that people avoid using PW with PHP 8.4.

It sounds like it'll be a tricky update, as null is what we use universally to identify that an argument value wasn't provided. PhpStorm finds 476 instances just in the core, and there's no one-fits-all solution. There really is no good substitute for null, but maybe \0 null string is the closest we can get. There are cases where we could replace it with false, blank string, or that null byte string, but might break anything that implements ProcessWire interfaces (likes modules), regardless of PHP version, because the argument definition has to change to accommodate this change in PHP. I'm not sure what the folks at PHP were thinking with this particular update. In any case, thanks for letting me know. I think I might have to get a new main/master version out and then come back to this. But the fact that you got Tracy working with it already gives me hope that maybe it won't be as difficult as it sounds.

adrianbj commented 2 days ago

Hey @ryancramerdesign - if it needs to allow any type, then you can simply leave off the type declaration entirely and then 8.4 doesn't care if you assign a default of null without the ?, eg $var = null.

Remember that you can also limit the types like string|array|null $var = null and that will also be OK.

I think in some cases false or an empty string might actually be more semantically correct, but will probably require a lot more care and testing to implement.

ryancramerdesign commented 2 days ago

@adrianbj so it's just those that already have a type declared in the arguments? Like (array $a = null) or (PageArray $products = null), etc? And an undeclared type argument like ($var = null) is okay? If so, that sounds much more manageable. Also leaves open the option of just dropping the type from the argument in some rare cases, as it's already declared in the phpdoc.

On Thu, Nov 28, 2024, 11:23 AM Adrian Jones @.***> wrote:

Hey @ryancramerdesign https://github.com/ryancramerdesign - if it needs to allow any type, then you can simply leave off the type declaration entirely and then 8.4 doesn't care if you assign a default of null without the ?, eg $var = null.

Remember that you can also limit the types like string|array|null $var = null and that will also be OK.

I think in some cases false or an empty string might actually be more semantically correct, but will probably require a lot more care and testing to implement.

— Reply to this email directly, view it on GitHub https://github.com/processwire/processwire-issues/issues/2000#issuecomment-2506464992, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACQEUCXHSGWNU4HEZZQNCL2C47PFAVCNFSM6AAAAABSMMVXKSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBWGQ3DIOJZGI . You are receiving this because you were mentioned.Message ID: @.***>

adrianbj commented 2 days ago

Yes @ryancramerdesign - that's my experience so far. And in actuality when trying to support PHP 7, you need to be careful because union types aren't available until 8, so the simplest thing in most cases seems to be to remove the type declaration (if you need to define the default as null), or change the default from null to an empty string or array.

ryancramerdesign commented 1 day ago

Thanks @BernhardBaumrock @adrianbj I've updated all the files that I could find that needed adjustments for this. I'm not yet running PHP 8.4 myself, please let me know if you spot any others.

adrianbj commented 1 day ago

Thanks @ryancramerdesign - I'll test here and get back to you with any further issues. Please note though that the ? required PHP7.1 so you'll need to adjust the requirements - currently it just states "7".

adrianbj commented 1 day ago

So far, everything looks good - thanks for the quick turnaround on this.

BernhardBaumrock commented 1 day ago

Hey @ryancramerdesign I just tried and had no issues on my quick testrun. Thx!