wppaste
WordPress

PclZipUtilPathInclusion( $p_dir, $p_path )

Source
wp-admin/includes/class-pclzip.php:5515

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$p_dir
$p_path

Performance profile

How much work a call to PclZipUtilPathInclusion() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
32–82

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 108.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost PclZipUtilPathInclusion() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$p_dir != "." && $p_path != "."32–62explode(), explode()
always39–72getcwd(), PclZipUtilTranslateWinPath(), explode(), explode()
always46–82getcwd(), PclZipUtilTranslateWinPath(), getcwd(), PclZipUtilTranslateWinPath(), explode(), explode()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10832–8222
8.510832–8222
8.410832–822212 fewer instructions than PHP 8.3
8.312032–9422
8.212032–94222 more instructions than PHP 8.1
8.111832–9422
7.411832–9422

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 1

Used by · 2

Source code

  function PclZipUtilPathInclusion($p_dir, $p_path)  {    $v_result = 1;     // ----- Look for path beginning by ./    if (   ($p_dir == '.')        || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {      $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);    }    if (   ($p_path == '.')        || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {      $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);    }     // ----- Explode dir and path by directory separator    $v_list_dir = explode("/", $p_dir);    $v_list_dir_size = sizeof($v_list_dir);    $v_list_path = explode("/", $p_path);    $v_list_path_size = sizeof($v_list_path);     // ----- Study directories paths    $i = 0;    $j = 0;    while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {       // ----- Look for empty dir (path reduction)      if ($v_list_dir[$i] == '') {        $i++;        continue;      }      if ($v_list_path[$j] == '') {        $j++;        continue;      }       // ----- Compare the items      if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != ''))  {        $v_result = 0;      }       // ----- Next items      $i++;      $j++;    }     // ----- Look if everything seems to be the same    if ($v_result) {      // ----- Skip all the empty items      while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;      while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;       if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {        // ----- There are exactly the same        $v_result = 2;      }      else if ($i < $v_list_dir_size) {        // ----- The path is shorter than the dir        $v_result = 0;      }    }     // ----- Return    return $v_result;  }

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-pclzip.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.