Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[2.5][Console] Use of undefined constant STDIN - assumed 'STDIN' #10795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
barryvdh opened this issue Apr 27, 2014 · 6 comments
Closed

[2.5][Console] Use of undefined constant STDIN - assumed 'STDIN' #10795

barryvdh opened this issue Apr 27, 2014 · 6 comments
Labels

Comments

@barryvdh
Copy link
Contributor

The new Console QuestionHelper uses the constant STDIN which is only available when using PHP in CLI modus. This is usually fine for the console, but in some cases command's are called through the web php.
This worked in 2.4, but doesn't work in 2.5, even when not using the QuestionHelper, because the QuestionHelper is instantiated in the Console Application getDefaultHelperSet(), and the STDIN constant is used in the constructor.

Cases where this lead to errors:

  • Calling a command through a webinterface
  • Just loading the console application in a ServiceProvider
    (But both are probably not best practices, but I came across both when testing Laravel 4.2-dev, which uses Symfony 2.5)

Possible fixes:

  • Not use STDIN in the constructor, but set it when the inputstream is first used.
  • Check if STDIN is defined, if not, define it manually (define('STDIN',fopen("php://stdin","r"));), can prevent errors in the rest of the helpers also, but probably don't have the desired effect.)

(cc @taylorotwell for Laravel)

@fabpot
Copy link
Member

fabpot commented Apr 28, 2014

ping @romainneutron

@romainneutron
Copy link
Contributor

Hello,

this is not a [Process] issue but a [Console] issue (@fabpot or @jakzal could you update the tag?).

Anyway, I've checked and there is no difference between version 2.4 and 2.5 of DialogHelper (that use STDIN constant) except its deprecation.
I'd rather not consider what you're reporting as a bug but expected behavior as this helper should not be used while handling a request (even less when there is no interaction with a user)

You can however inject your own inputStream using DialogHelper::setInputStream or QuestionHelper::setInputStream if you want to hack this object

@barryvdh barryvdh changed the title [2.5][Process] Use of undefined constant STDIN - assumed 'STDIN' [2.5][Console] Use of undefined constant STDIN - assumed 'STDIN' Apr 28, 2014
@jakzal jakzal added Console and removed Process labels Apr 28, 2014
@taylorotwell
Copy link
Contributor

If it worked in 2.4 and does not work in 2.5 that is a breaking change / bug, no?—
Sent from Mailbox

On Mon, Apr 28, 2014 at 5:44 AM, Romain Neutron [email protected]
wrote:

Hello,
this is not a [Process] issue but a [Console] issue (@fabpot or @jakzal could you update the tag?).
Anyway, I've checked and there is no difference between version 2.4 and 2.5 of DialogHelper (that use STDIN constant) except its deprecation.
I'd rather not consider what you're reporting as a bug but expected behavior as this helper should not be used while handling a request (even less when there is no interaction with a user)

You can however inject your own inputStream using DialogHelper::setInputStream or QuestionHelper::setInputStream if you want to hack this object

Reply to this email directly or view it on GitHub:
#10795 (comment)

@barryvdh
Copy link
Contributor Author

Sorry, I updated the title.

I was talking about the QuestionHelper, not DialogHelper. QuestionHelper is new in 2.5, right?

DialogHelper isn't causing problems, because it doesn't get to a point where it actually uses STDIN. QuestionHelper hower, uses STDIN in its constructor, which is called in the getDefaultHelperSet()

Setting the InputStream doesn't help, because the problem isn't that the InputStream doesn't work, the problem is dat it doesn't recognize the STDIN constant.

@barryvdh
Copy link
Contributor Author

Testcase, with only requiring symfony/console:

<?php
error_reporting(-1);
ini_set("display_errors", 1);
require 'vendor/autoload.php';
$console = new Symfony\Component\Console\Application();

When I require "symfony/console": "2.4.x", this runs fine. When I require 2.5.x:
Notice: Use of undefined constant STDIN - assumed 'STDIN' in /var/www/html/stdin/public/vendor/symfony/console/Symfony/Component/Console/Helper/QuestionHelper.php on line 33

@fabpot fabpot closed this as completed in 3a5a525 Apr 28, 2014
fabpot added a commit that referenced this issue Apr 28, 2014
… when STDIN is not declared (romainneutron)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[Console] Fix #10795: Allow instancing Console Application when STDIN is not declared

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10795
| License       | MIT

Commits
-------

3a5a525 [Console] Fix #10795: Allow instancing Console Application when STDIN is not declared
@barryvdh
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants