Skip to content

Garbage output from readline_callback_handler_install (CharacterReader) #1090

@jbboehr

Description

@jbboehr

I spent a while hunting this one down. The call to readline_callback_handler_install in CharacterReader is causing some junk output (see below) that was breaking the CSV output. Clearing out TERM and COLORTERM also prevents the issue.

I don't know if this should be a bug for upstream or not, but it could be worked around by not calling readline_callback_handler_install unless you're actually using readline functionality. Right now, it appears to be called in all commands, even if CharacterReader is not being used.

$ COLORTERM="truecolor" TERM="xterm-256color" php -r "readline_callback_handler_install('', function (): void {});" | xxd
00000000: 1b5b 3f32 3030 3468 1b5b 3f32 3030 346c  .[?2004h.[?2004l
00000010: 0d                                       .

$ COLORTERM= TERM= php -r "readline_callback_handler_install('', function (): void {});" | xxd

$ COLORTERM="truecolor" TERM="xterm-256color" php -r "" | xxd

$ docker run --rm -ti  --env COLORTERM="truecolor" --env TERM="xterm-256color" php -r "readline_callback_handler_install('', function (): void {});" | xxd
00000000: 1b5b 3f32 3030 3468 1b5b 3f32 3030 346c  .[?2004h.[?2004l
                                                                   00000010: 0d                                       .

$ uname -a
Linux nixos 6.7.6-xanmod1 #1-NixOS SMP PREEMPT_DYNAMIC Tue Jan  1 00:00:00 UTC 1980 x86_64 GNU/Linux

$ php --version
PHP 8.2.16 (cli) (built: Feb 13 2024 15:22:59) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.16, Copyright (c), by Zend Technologies

$ php -m | grep readline
readline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions