Skip to content

Stdlib: utf8_encode()/utf8_decode() — scalar-to-string coercion (ext/standard/basic_functions.c parity) #4317

Description

@PurHur

Category

stdlib

Problem

utf8_encode() and utf8_decode() reject non-string operands with LogicException instead of coercing scalars like Zend.

php-src reference

Repro

Maintainer script: test/repro-maintainer/utf8_encode_scalar.php

HARNESS_DOCKER_RUN_OPTS='--memory=8g --cpus=2' ./script/docker-exec.sh -- bash -lc '
  source script/php-env.sh
  php test/repro-maintainer/utf8_encode_scalar.php
  php bin/vm.php test/repro-maintainer/utf8_encode_scalar.php
'
Mode utf8_encode(65) / utf8_decode(195)
Zend string(2) "65" / string(3) "195"
VM LogicException — only supports strings

Scope

Area Files
VM ext/standard/utf8_encode.php, ext/standard/utf8_decode.php
Helpers VmReflection::stringArg() or shared scalar coercion (see #4310 htmlspecialchars)
JIT JitUtf8Latin1 — already uses jitString(); align VM

Done when

  • utf8_encode() / utf8_decode() coerce int/float/bool to string before ISO-8859-1 ↔ UTF-8 transform
  • Invalid types (array/object/resource) throw TypeError like Zend, not LogicException
  • test/compliance/cases/stdlib/utf8_encode_decode_scalar.phpt passes VM + JIT

Verification

  • Add test/compliance/cases/stdlib/utf8_encode_decode_scalar.phpt
  • VM + JIT filter; AOT if lowering exists

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 machineenhancementNew feature or requestimplementation-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