Table of Contents

PHP RFC: Fix base_convert() and related PHP lib functions

Introduction

_php_math_basetozval(), which underlies the base_convert(), bindec(), octdec(), and hexdec() userspace functions, uses a custom parsing loop which ignores any characters in the input string which aren't in the [0-9a-zA-Z] set. This results in input strings containing garbage being quietly processed as though they were valid numeric strings, for example:

base_convert(1.5, 10, 10); -> 15
base_convert("&%^&%^#%#^%4#%#(%*!2#(%*", 10, 10); -> 42

Equally confusing, ordinals greater or equal to the base being converted are also ignored:

base_convert("12304560", 2, 10); -> 4

Proposal

One of the following solutions:

Targeting Version

7.next