Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion includes/ReverseWithdrawal/ReverseWithdrawal.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public function __clone() {
* Unserializing instances of this class is forbidden.
*
* @since 3.5.1
*
* @param array $data Unserialized data.
*/
public function __wakeup() {
public function __unserialize( array $data ): void {
$message = ' Backtrace: ' . wp_debug_backtrace_summary();
_doing_it_wrong( __METHOD__, $message . esc_html__( 'Unserializing instances of this class is forbidden.', 'dokan-lite' ), DOKAN_PLUGIN_VERSION ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
Comment on lines +38 to 43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Find and examine the ReverseWithdrawal.php file
find . -name "ReverseWithdrawal.php" -type f

Repository: getdokan/dokan

Length of output: 216


🏁 Script executed:

# Read the file to see the full method context
if [ -f "includes/ReverseWithdrawal/ReverseWithdrawal.php" ]; then
  cat -n "includes/ReverseWithdrawal/ReverseWithdrawal.php"
fi

Repository: getdokan/dokan

Length of output: 3700


🏁 Script executed:

# Check if there's a __serialize method (companion to __unserialize)
rg "__serialize|__unserialize" --context 5 "includes/ReverseWithdrawal/ReverseWithdrawal.php"

Repository: getdokan/dokan

Length of output: 502


🏁 Script executed:

# Check for phpcs directives or linter configuration in the repository
find . -name "phpcs.xml*" -o -name ".phpcs.xml*" -o -name "phpstan.neon*" -o -name "psalm.xml*" | head -5

Repository: getdokan/dokan

Length of output: 74


🏁 Script executed:

# Check phpcs configuration
cat phpcs.xml.dist

Repository: getdokan/dokan

Length of output: 9931


🏁 Script executed:

# Look for patterns of unused parameter handling in the codebase
rg "unset\(" --context 2 | head -30

Repository: getdokan/dokan

Length of output: 1827


🏁 Script executed:

# Check if there are phpcs inline suppressions for unused parameters in similar contexts
rg "phpcs:ignore.*unused|@phpstan-ignore-next-line" --context 2 | head -30

Repository: getdokan/dokan

Length of output: 40


🏁 Script executed:

# Search for other __unserialize or magic methods in the codebase to see patterns
rg "__unserialize|__serialize|__clone" --context 3

Repository: getdokan/dokan

Length of output: 2775


🏁 Script executed:

# Check if ChainableContainer.php has the same issue and if it's addressed
cat -n includes/Traits/ChainableContainer.php | grep -A 5 "__unserialize"

Repository: getdokan/dokan

Length of output: 457


🏁 Script executed:

# Verify PHP magic method signature requirements for __unserialize
web_search "PHP __unserialize magic method signature requirements"

Repository: getdokan/dokan

Length of output: 108


🌐 Web query:

PHP __unserialize magic method signature parameter required

💡 Result:

Short answer: The required signature is

public function __unserialize(array $data): void

Details:

  • __unserialize was introduced as part of the new serialization API in PHP 7.4. [1][2]
  • The method must be public and accept a single parameter typed as array; using a different signature (including different parameter type or missing the parameter) is a fatal error. [1]
  • It should not return a value (declare return type void). [1][3]

Sources:
[1] PHP Manual — Magic Methods.
[2] PHP RFC: Phasing out Serializable (introducing __serialize/__unserialize).
[3] PHP Manual — examples for builtins showing signature (e.g. SplFixedArray/DateTime __unserialize).


Add unset( $data ); to suppress unused parameter warning—apply same fix to ChainableContainer.php for consistency.

The $data parameter is required by the PHP magic method signature but unused in the implementation. While functionally correct, linters flag it. The same unused parameter issue exists identically in includes/Traits/ChainableContainer.php at line 31, so both should be updated consistently.

Suggested fix
 public function __unserialize( array $data ): void {
+    unset( $data ); // Intentionally unused.
     $message = ' Backtrace: ' . wp_debug_backtrace_summary();
     _doing_it_wrong( __METHOD__, $message . esc_html__( 'Unserializing instances of this class is forbidden.', 'dokan-lite' ), DOKAN_PLUGIN_VERSION ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
*
* @param array $data Unserialized data.
*/
public function __wakeup() {
public function __unserialize( array $data ): void {
$message = ' Backtrace: ' . wp_debug_backtrace_summary();
_doing_it_wrong( __METHOD__, $message . esc_html__( 'Unserializing instances of this class is forbidden.', 'dokan-lite' ), DOKAN_PLUGIN_VERSION ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
*
* `@param` array $data Unserialized data.
*/
public function __unserialize( array $data ): void {
unset( $data ); // Intentionally unused.
$message = ' Backtrace: ' . wp_debug_backtrace_summary();
_doing_it_wrong( __METHOD__, $message . esc_html__( 'Unserializing instances of this class is forbidden.', 'dokan-lite' ), DOKAN_PLUGIN_VERSION ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
🧰 Tools
🪛 PHPMD (2.15.0)

41-41: Avoid unused parameters such as '$data'. (undefined)

(UnusedFormalParameter)

🤖 Prompt for AI Agents
In `@includes/ReverseWithdrawal/ReverseWithdrawal.php` around lines 38 - 43, The
__unserialize method in ReverseWithdrawal (and the identical method in the
ChainableContainer trait/class) accepts the required array $data parameter but
never uses it, triggering linter warnings; to fix, add unset( $data ); at the
start (or before returning) of the __unserialize( array $data ): void method in
ReverseWithdrawal.php and the same __unserialize implementation in
includes/Traits/ChainableContainer.php so the parameter is explicitly marked as
unused and the linter warning is suppressed.

}
Expand Down
4 changes: 3 additions & 1 deletion includes/Traits/ChainableContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
* Unserializing instances of this class is forbidden.
*
* @since 3.7.21
*
* @param array $data Unserialized data.
*/
public function __wakeup() {
public function __unserialize( array $data ): void {

Check warning on line 31 in includes/Traits/ChainableContainer.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $data is never used
$message = ' Backtrace: ' . wp_debug_backtrace_summary();
_doing_it_wrong( __METHOD__, $message . esc_html__( 'Unserializing instances of this class is forbidden.', 'dokan-lite' ), DOKAN_PLUGIN_VERSION ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
Expand Down
Loading