php / php/php-src

Interactive shell doesn't complete property names

Open
#17,670 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: readline Feature SAPI: cli
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

According to the documentation:

The interactive shell also features tab completion for functions, constants, class names, variables, static method calls and class constants.

Only function, class and method names seems to be completing when hitting the TAB key.

Also, the completion is not contextualized: after $, it should be only variable names (not function and class names), and after -> it should be only property and method names of the current object.

The following command to run the interactive shell:

php -a
Completion of variable name

The following shell code:

php > $container = 'hello';
php > $co [⇥TAB]

Resulted in this output:

Collator                     collator_get_strength        constant                    
collator_asort               collator_set_attribute       convert_uudecode            
collator_compare             collator_set_strength        convert_uuencode            
collator_create              collator_sort                copy                        
collator_get_attribute       collator_sort_with_sort_keys cos                         
collator_get_error_code      compact                      cosh                        
collator_get_error_message   CompileError                 count                       
collator_get_locale          connection_aborted           count_chars                 
collator_get_sort_key        connection_status            Countable     

But I expected this output instead:

$container
Completion of property name

The following shell code:

php > $object = (object) ['foo' => 'bar'];
php > $object->fo [⇥TAB]

Resulted in this output:

fopen                     forward_static_call       forward_static_call_array

But I expected this output instead:

foo
PHP version
PHP 8.4.3 (cli) (built: Jan 15 2025 01:03:17) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.4.3, Copyright (c) Zend Technologies
    with Xdebug v3.4.1, Copyright (c) 2002-2025, by Derick Rethans
    with Zend OPcache v8.4.3, Copyright (c), by Zend Technologies
PHP Version

PHP 8.4.3

Operating System

Mac 15.3 (24D60)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running php -a and reproducing the variable and property completion examples from the issue. Trace the interactive shell's completion entry point and determine how the current candidates are selected. Done means $co completes only $container and $object->fo completes foo, with the documented completion behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.