Skip to content
Merged
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
42 changes: 40 additions & 2 deletions ext/standard/ArrayColumnJitHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace PHPCompiler\ext\standard;

use PHPCompiler\MethodVisibility;
use PHPCompiler\VM\ClassProperty;
use PHPCompiler\VM\EnumCaseSupport;
use PHPCompiler\VM\HashTable;
use PHPCompiler\VM\ObjectEntry;
use PHPCompiler\VM\Variable;

/**
Expand Down Expand Up @@ -176,11 +179,46 @@ private static function readColumnFromRow(Variable $row, string|int $field): ?Va

return EnumCaseSupport::getProperty($object, $propName);
}
if (!$object->hasProperty($propName)) {

// php-src php_array_column: silent public property read — no __get (#23511).
return self::readPublicObjectColumnProperty($object, $propName);
}

return null;
}

/**
* Zend array_column object path: only public declared/dynamic properties; never __get.
*
* @see https://github.com/php/php-src/blob/master/ext/standard/array.c php_array_column
*/
private static function readPublicObjectColumnProperty(ObjectEntry $object, string $propName): ?Variable
{
$meta = self::findDeclaredInstanceProperty($object, $propName);
if (null !== $meta) {
if (!MethodVisibility::isPublic($meta->visibility)) {
return null;
}
if (!$object->hasPropertyForMeta($meta)) {
return null;
}

return $object->getPropertyForMeta($meta)->resolveIndirect();
}
// Undeclared dynamic properties are public; missing slots must not invoke __get.
if (!$object->hasProperty($propName)) {
return null;
}

return $object->getProperty($propName)->resolveIndirect();
return $object->getProperty($propName)->resolveIndirect();
}

private static function findDeclaredInstanceProperty(ObjectEntry $object, string $propName): ?ClassProperty
{
foreach ($object->class->properties as $prop) {
if ($prop->name === $propName) {
return $prop;
}
}

return null;
Expand Down
30 changes: 30 additions & 0 deletions test/compliance/cases/stdlib/array_column_private_get.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
stdlib array_column() skips private/protected object props (no __get) (#23511)
--FILE--
<?php
class R {
private $name;
public function __construct(string $n) { $this->name = $n; }
public function __get(string $k): string { return $this->name; }
}
echo json_encode(array_column([new R('x'), new R('y')], 'name')), "\n";
class P {
public function __construct(public string $name) {}
}
echo json_encode(array_column([new P('a'), new P('b')], 'name')), "\n";
class Prot {
protected $name;
public function __construct(string $n) { $this->name = $n; }
public function __get(string $k): string { return $this->name; }
}
echo json_encode(array_column([new Prot('z')], 'name')), "\n";
class Dyn {
public function __get(string $k) { return 'magic'; }
}
echo json_encode(array_column([new Dyn()], 'name')), "\n";
?>
--EXPECT--
[]
["a","b"]
[]
[]
8 changes: 8 additions & 0 deletions test/repro/array_column_private_get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
// #23511 — array_column() must not read private props via storage/__get
class R {
private $name;
public function __construct(string $n) { $this->name = $n; }
public function __get(string $k): string { return $this->name; }
}
echo json_encode(array_column([new R('x'), new R('y')], 'name')), "\n";