|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53040 PHP crash/failure when called from bash-completion
Submitted: 2010-10-11 03:10 UTC Modified: 2011-03-01 08:30 UTC
From: myselfasunder at gmail dot com Assigned:
Status: Closed Package: CGI/CLI related
PHP Version: 5.3.3 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: myselfasunder at gmail dot com
New email:
PHP Version: OS:


 [2010-10-11 03:10 UTC] myselfasunder at gmail dot com
Calling PHP shell-scripts in any way (even if it doesn't do anything) from a bash-completion script causes the bash-completion script to fail (pressing TAB causes erratic spacing and tabbing at the console rather than producing options for completion). Bash and Perl calls work fine.

This refers to calling PHP in any of the following ways:
o php -r '..'
o php script.php
o ./script.php (this references '/usr/bin/php' with a shebang at the top)

I even tried calling Perl from the Bash, and then calling PHP from the Perl. No change in behavior. I tried with both 5.2 and the latest version of 5.3 .

Test script:
No test script necessary. Executing "php -r ''" in a bash completion script causes the failure.

Contents of ~/completiontest can be found at:

You can commit this to the current bash-completion configuration by executing:

  ~$ . completiontest

To test without PHP, just comment-out the PHP call.

Expected result:
dustin@ubuntu:~$ . completiontest
dustin@ubuntu:~$ completiontest --<TAB><TAB>
--help     --verbose  --version
dustin@ubuntu:~$ completiontest --

Actual result:
dustin@ubuntu:~$ . completiontest
dustin@ubuntu:~$ completiontest --        |<-- Cursor moves to here.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-01 08:30 UTC] myselfasunder at gmail dot com
-Status: Open +Status: Closed
 [2011-03-01 08:30 UTC] myselfasunder at gmail dot com
Even the existence of a PHP call in a bash_completion.d script or any referenced Bash script may cause a complete completion failure, even when all STDERR and STDOUT output is suppressed (redirected to /dev/null), depending on what row it's effectively referenced from in the top-most bash_completion.d script. From what little material there is about this on the Internet, it appears that this problem might be a result of particular Ubuntu versions. No matter.

Bash completion with PHP works fine when used with the CGI variant. For example:

> /etc/bash_completion.d/foo
(Extends example at
    local cur opts


    opts=`echo "$COMP_CWORD:$BUFFER" | /tmp/completiontest.php`

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0

complete -F _foo foo

> /tmp/completiontest.php
#!/usr/bin/php5-cgi -q

// Just to 1) prevent writing to the bash_completion.d directory, and 
// 2) nail-down where our output file, below, will end up.

// Grab completion information from STDIN. 
// Ex:
//   dustin@mx4:~$ foo --arg1 --arg2 --to_be_complet<TAB>^C
//   dustin@mx4:~$ cat /tmp/stdin.txt
//   3:foo,--arg1,--arg2,--to_be_complet
// Format of received STDIN information is "<number of tokens>:<comma-sep list of tokens>"
file_put_contents('stdin.txt', file_get_contents('php://stdin'));

// Output the space-separated completion possibilities.
print("--abc --def");
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Aug 04 04:01:24 2021 UTC