Skip to content

Stdlib: filter_var() — full ext/filter parity (filters, flags, options array, warnings) #4403

Description

@PurHur

Category

stdlib · php-src-strict · spec refresh 2026-06-20

Problem

filter_var() currently implements a very small subset (validate int + validate email) and restricts $options to null|int only. Zend/php-src supports many filters, options arrays, and flag semantics (including FILTER_NULL_ON_FAILURE, FILTER_FLAG_*, FILTER_REQUIRE_ARRAY, default behavior, and correct return types + warnings).

Concrete dispatch failure (2026-06-20 probe)

FILTER_VALIDATE_IP constant resolves to 275, but filter_var('127.0.0.1', FILTER_VALIDATE_IP) emits Warning: filter_var(): Unknown filter with ID 275 and returns false. Zend returns '127.0.0.1.

Related narrow issues: #9588 (named FILTER_* constants rejected at compile), #4934 (FILTER_VALIDATE_BOOL), #9860 (JIT email path).

php-src reference

Repro (today)

<?php
declare(strict_types=1);

// 1) FILTER_VALIDATE_IP — constant known, dispatch missing
var_export(filter_var('127.0.0.1', FILTER_VALIDATE_IP));
echo "\n";
var_export(filter_var('not-an-ip', FILTER_VALIDATE_IP));
echo "\n";

// 2) Options array should be accepted for validate int.
var_export(filter_var('42', FILTER_VALIDATE_INT, ['options' => ['min_range' => 50]]));
echo "\n";

// 3) URL validation is missing.
var_export(filter_var('https://example.com', FILTER_VALIDATE_URL));
echo "\n";

// 4) FILTER_NULL_ON_FAILURE should return null instead of false.
var_export(filter_var('not-an-int', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE));
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php 2>&1
'

Expected (Zend):

  • IP validate: '127.0.0.1' / false
  • false for the min_range case
  • URL validate success string or false
  • null for FILTER_NULL_ON_FAILURE case

VM today: IP case warns Unknown filter with ID 275; others partial/missing.

Scope (this repo)

Path Work
ext/filter/ or ext/standard/ Register full filter dispatch table
ext/standard/filter_var.php, VmFilter.php VM SSOT per filter
lib/JIT/ defer until VM parity; note in matrix
Tests test/compliance/cases/stdlib/filter_var_validate_ip.phpt + umbrella PHPTs

PHP-in-PHP: implement filters in ext/ + shared validation helpers; #9860 shrinks JIT email LLVM after VM parity.

Done when

  • filter_var('127.0.0.1', FILTER_VALIDATE_IP) returns validated string (no unknown-filter warning)
  • Options arrays + FILTER_NULL_ON_FAILURE behave per Zend on a starter filter set (int, bool, ip, url, email)
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter filter_var' green for new PHPTs
  • php script/capability-matrix.php updated

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions