Skip to content

Incorrect result in substr #16636

@YuanchengJiang

Description

@YuanchengJiang

Description

The following code:

<?php
namespace foo;
const foo = 1;
const foo = 2;
interface MyInterface {
    const TEST_CONSTANT = true;
}
class ParentClass implements MyInterface { }
class ChildClass extends ParentClass { }
echo (is_subclass_of('ChildClass', 'MyInterface') ? 'true' : 'false') . "\n";
echo (defined('ChildClass::TEST_CONSTANT') ? 'true' : 'false') . "\n";
echo (is_subclass_of('ParentClass', 'MyInterface') ? 'true' : 'false') . "\n";
echo (defined('ParentClass::TEST_CONSTANT') ? 'true' : 'false') . "\n";
$x1=1;
$x2=1;
var_dump('substr');
$callret=substr($x1,$x2,$x1);
print_r($callret);
var_export($callret);
debug_zval_dump($callret);
?>

Resulted in this output (non-JIT):

false
false
false
false
string(6) "substr"
''string(0) "" interned

and (JIT 1211):

false
false
false
false
string(6) "substr"

Fatal error: Uncaught TypeError: substr(): Argument #2 ($offset) must be of type int, string given in /tmp/test.php:17

PHP Version

nightly

Operating System

ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions