Opened 2 months ago
Last modified 5 weeks ago
#62159 new defect (bug)
Creation of dynamic property ftp::$features is deprecated (PHP 8.2)
Reported by: | kmurphyzuora | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | major | Version: | |
Component: | Administration | Keywords: | dev-feedback has-patch |
Focuses: | php-compatibility | Cc: |
Description
<?php Deprecated: Creation of dynamic property ftp::$features is deprecated in /var/www/html/wp-admin/includes/class-ftp.php on line 151 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-admin/includes/class-ftp.php:151) in /var/www/html/wp-admin/includes/misc.php on line 1438 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-admin/includes/class-ftp.php:151) in /var/www/html/wp-includes/functions.php on line 7108 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-admin/includes/class-ftp.php:151) in /var/www/html/wp-admin/admin-header.php on line 9
Change History (8)
#1
@
2 months ago
- Focuses php-compatibility added
- Keywords dev-feedback added
- Severity changed from normal to major
#2
@
2 months ago
Good morning,
Adding a local property does fix it from my initial testing. One thing I found was this is also a method with the same name.
<?php $this->features // Is never accessed as an array
<?php $this->_features // Is accessed as an array
<?php // Line 491 function features() { if(!$this->_exec("FEAT", "features")) return FALSE; if(!$this->_checkCode()) return FALSE; $f=preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY); $this->_features=array(); foreach($f as $k=>$v) { $v=explode(" ", trim($v)); $this->_features[array_shift($v)]=$v; } return true; }
<?php class ftp_base // Don't see any polymorphism with any other class
I created a branch with my fix, but on my work computer I don't have push write to the https://github.com/WordPress/wordpress-develop repository. I'm going to chat with my boss today and see if I can work on this fix using my work computer.
This ticket was mentioned in PR #7540 on WordPress/wordpress-develop by @debarghyabanerjee.
2 months ago
#3
- Keywords has-patch added
Trac Ticket: Core-62159
## Problem Statement
In PHP 8.2, the creation of dynamic properties is deprecated, which affects the ftp class where the property $features
was previously created dynamically. This change could lead to warnings and potential issues in future versions of PHP.
## Solution
This PR addresses the issue by adding a class field $features
to the ftp class. This ensures compliance with PHP 8.2 standards and eliminates the use of dynamic properties.
## Changes Made
- Added a class property $features to the ftp class.
## Benefits
- Resolves deprecation warnings in PHP 8.2, ensuring compatibility with future PHP versions.
- Improves code quality and maintainability by defining class properties explicitly.
## Testing
- Verified that the changes do not introduce any errors or warnings in PHP 8.2.
- Conducted unit tests to ensure that the functionality of the ftp class remains intact.
@hellofromTonya commented on PR #7540:
2 months ago
#4
Hello @Debarghya-Banerjee,
Thank you for contributing this patch. Great job writing the PR's description 🏆
Where should this dynamic property be declared? By itself seems out-of-place. What about grouping it with the public variables?
@hellofromTonya commented on PR #7540:
2 months ago
#5
Huh, I don't see where this property is used in the class or the child classes. The private _features
property is used, but not the public one. Huh.
I wonder ... Could this property be removed? @costdev what do you think?
#6
@
7 weeks ago
I think a better solution to the PHP deprecated problem would be to remove the line from the constructor.
If I've understood correctly there is a class:
- Variable $_features
- Method $features...which uses that class variable
The class constructor has lines:
$this->_features=array();
...
$this->features=array();
The second one, which is producing the PHP deprecated error, shouldn't have been added. Deleting that line would be the neatest fix.
#7
@
7 weeks ago
Good afternoon,
From what I'm seeing in the base/extended classes removing the property wouldn't effect anything.
In my opinion removing it from the constructor is the cleanest solution.
Keith
@debarghyabanerjee commented on PR #7540:
5 weeks ago
#8
Hi @hellofromtonya , I am updating the PR and removing the property, since after checking found that this field is not being used anywhere, hence it's better to remove, I am updating the PR and pushing the latest code.
In /var/www/html/wp-admin/includes/class-ftp.php, add a declaration for the features property within the FTP class.
I feel this should fix it.