Skip to content

Add default value for sortOrder in Plugins#259

Open
jlnarvaez wants to merge 2 commits into
AdobeDocs:mainfrom
jlnarvaez:patch-4
Open

Add default value for sortOrder in Plugins#259
jlnarvaez wants to merge 2 commits into
AdobeDocs:mainfrom
jlnarvaez:patch-4

Conversation

@jlnarvaez
Copy link
Copy Markdown
Contributor

Purpose of this pull request

This pull request (PR) add specification about the default value of sortOrder in Plugins declaration. (https://github.com/magento/magento2/blob/fcebd3a4ad2a6863af2e2092f5e548cbd81cb0f8/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php#L160)

Affected pages

Closes #234

@meker12
Copy link
Copy Markdown
Contributor

meker12 commented May 4, 2026

Update validated against the code base:

I'll help you validate whether this default value for plugin sortOrder is correct. Let me search the Magento 2 repository to verify this information.Based on my search of the Magento 2 codebase, the default value for plugin sortOrder is indeed PHP_INT_MIN, and this is correct.

Evidence

The code confirms this in two key locations:

uasort($plugins, function ($itemA, $itemB) {
    return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN);
});
protected function _sort($itemA, $itemB)
{
    return ($itemA['sortOrder'] ?? PHP_INT_MIN) - ($itemB['sortOrder'] ?? PHP_INT_MIN);
}

What This Means

When a plugin's sortOrder is not explicitly defined, it defaults to PHP_INT_MIN (the smallest possible integer value). This ensures that plugins without a specified sort order run first in the execution chain, while plugins with higher sort order values run later. The sorting is done in ascending order, so lower values execute before higher values.

@meker12 meker12 self-assigned this May 4, 2026
@meker12 meker12 added content-quality Language, formatting, SEO metadata, authoring standards compliance technical Updates to the code or processes that alter the technical content of the doc and removed content-quality Language, formatting, SEO metadata, authoring standards compliance labels May 4, 2026
@github-project-automation github-project-automation Bot moved this from 📋 Needs Review to 👍 Approved in Commerce - Pull Requests May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

technical Updates to the code or processes that alter the technical content of the doc

Projects

Status: 👍 Approved

Development

Successfully merging this pull request may close these issues.

What is the default value for a plugin's sortOrder?

2 participants