4

I am using Netbeans to develop PHP console application samples (just for fun and proof of concept). readline is a library binding that takes a string from the console. For example, be read.php a file with the following content:

<?php
$line = readline("Name: ");
echo "$line\n";
?>

I can execute it as (gnome-terminal + bash)

php read.php

And it will outputs like

Name: Firstname Lastname
Firstname Lastname

So far so good.

When I put this code inside Netbeans, the console also inside Netbeans, it does not echo the prompt "Name: ". For example, this is a screenshot took after SHIFT+F6 pressed Sample screenshot

Any insights towards how to overcome this?

Lourenco
  • 2,772
  • 2
  • 15
  • 21

1 Answers1

0

According to an answer in Trying to read from the console in Java IDEs don't normally provide a valid TTY which is required for this to work.

What you could do instead is create a helper function such as this:

function readlineHelper(?string $prompt = null): string|false
{
    if ($propmpt)
    {
        echo $prompt;
    }

    return readline();
}
Eborbob
  • 1,905
  • 1
  • 15
  • 30