php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17323 posix_isatty wants a long instead of resource
Submitted: 2002-05-20 19:08 UTC Modified: 2002-06-03 18:20 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: polone at townnews dot com Assigned:
Status: Closed Package: POSIX related
PHP Version: 4.2.0 OS: Linux
Private report: No CVE-ID: None
 [2002-05-20 19:08 UTC] polone at townnews dot com
The bug seems rather simple. Using command-line PHP, the following fragment should work:

#!/usr/bin/php -q
<?php

   $fd = fopen('php://stdout','w');
   if (posix_isatty($fd))
      print "yes, it is a terminal\n";
   else
      print "no, it is not a terminal\n";

?>

However, it appears that the function definition requires a long passed, instead of a resource. The error message reported is:

dns:root-/usr/bin> ./test.php
PHP Warning:  posix_isatty() expects parameter 1 to be long, resource given in /usr/bin/test.php on line 4
<br />
<b>Warning</b>:  posix_isatty() expects parameter 1 to be long, resource given in <b>/usr/bin/test.php</b> on line <b>4</b
><br />
no, it is not a terminal

A workaround appears to be the following:

#!/usr/bin/php -q
<?php

   $fd = fopen('php://stdout','w');
   settype($fd,'int');
   if (posix_isatty($fd))
      print "yes, it is a terminal\n";
   else
      print "no, it is not a terminal\n";

?>

The explicit type-cast fixes the problem. Maybe I have settings in the php.ini file wrong, but I don't think this function should behave like this. Perhaps it requires just a change to the source. This is also broke with posix_ttyname(). Am I suppose to acquire a file descriptor another way?

Regards,

Patrick O'Lone

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-20 19:31 UTC] mfischer@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

Will also be in 4.2.2 (if there will be a release).
 [2002-05-22 03:54 UTC] mfischer@php.net
Reopening, problem not completely fixed, assigning to me.
 [2002-06-02 10:06 UTC] mfischer@php.net
Critical before 4.3 release.

Best thing is probably to use the old-style code, if someone has a better idea, speak up.
 [2002-06-03 11:04 UTC] polone at townnews dot com
Why not just type cast a ZEND_RESOURCE to a ZEND_LONG?
 [2002-06-03 11:50 UTC] mfischer@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

Please try CVS HEAD, it should be fixed now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 21:01:29 2024 UTC