Category
language
Problem
PHP’s declare(strict_types=1) changes how scalar parameter type declarations behave at call sites. Zend enforces:
- With
strict_types=1 in the caller file: scalar mismatches raise TypeError (no coercion).
- With
strict_types=0 (default): scalar mismatches may coerce (e.g. '1' to 1) depending on target type.
Parity gap: this compiler must match Zend’s strictness rules (especially “caller controls strictness”), error types/messages, and behavior for int, float, string, bool parameters and return types.
php-src reference
Zend/zend_execute.c — argument type verification / coercion paths
Zend/zend_compile.c — declare(strict_types=1) compile-time flag propagation
- Tests:
Zend/tests/type_declarations/strict_types/*
Repro
Create 3 files:
callee.php:
<?php
function takesInt(int $x): int { return $x; }
caller_weak.php:
<?php
require __DIR__.'/callee.php';
var_dump(takesInt('1'));
caller_strict.php:
<?php
declare(strict_types=1);
require __DIR__.'/callee.php';
try {
takesInt('1');
echo "NO ERROR\n";
} catch (Throwable $e) {
echo get_class($e), "\n";
}
Run:
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php caller_weak.php
php caller_strict.php
php bin/vm.php caller_weak.php
php bin/vm.php caller_strict.php'
Expected (Zend):
caller_weak.php prints int(1)
caller_strict.php prints TypeError
Scope
- Compiler: ensure strict_types flag is stored per compilation unit and used at call sites
- VM: align scalar coercion + TypeError messages with Zend
- Tests: add
test/compliance/cases/language/strict_types_scalar_args.phpt
Done when
Category
languageProblem
PHP’s
declare(strict_types=1)changes how scalar parameter type declarations behave at call sites. Zend enforces:strict_types=1in the caller file: scalar mismatches raiseTypeError(no coercion).strict_types=0(default): scalar mismatches may coerce (e.g.'1'to1) depending on target type.Parity gap: this compiler must match Zend’s strictness rules (especially “caller controls strictness”), error types/messages, and behavior for
int,float,string,boolparameters and return types.php-src reference
Zend/zend_execute.c— argument type verification / coercion pathsZend/zend_compile.c—declare(strict_types=1)compile-time flag propagationZend/tests/type_declarations/strict_types/*Repro
Create 3 files:
callee.php:caller_weak.php:caller_strict.php:Run:
Expected (Zend):
caller_weak.phpprintsint(1)caller_strict.phpprintsTypeErrorScope
test/compliance/cases/language/strict_types_scalar_args.phptDone when
TypeErrorwith close-to-Zend message