|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-10-13 19:45 UTC] per at perit dot se
Description: ------------ --- From manual page: https://php.net/function.exec --- The documentation specifies syntax exec ( string $command [, array &$output [, int &$return_var ]] ) : string This syntax breaks PHP, and according to numerous internet articles like https://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available explaining it has been so a while: > As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. Please update the documentation with correct syntax, and if/when it differs for specific versions, please note the version and change in question - now it incorrectly claims to be valid for "(PHP 4, PHP 5, PHP 7)" Test script: --------------- $ cat > test-ref-arg.php <?php exec ( "pwd", &$output ); echo "Got output: "; var_dump($output); $ php test-ref-arg.php PHP Fatal error: Call-time pass-by-reference has been removed in /home/xx/IMPORT/test-ref-arg on line 2 /opt/rh/rh-php73/root/bin/php test-ref-arg.php PHP Parse error: syntax error, unexpected '&', expecting ')' in /home/xx/test-ref-arg.php on line 2 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
The documentation is showing you the *signature* of the function, not the *usage*. An actual declaration in userland would in fact look something like this: function exec (string $command, ?array &$output=null, ?int &$return_var=null): string { .... } The manual page could do with an example of using those params though, which would look something like this: $output=null; $retval=null; exec('whoami', $output, $retval); echo "Returned with status $retval and output $output";