note 126096 added to function.getopt

From: Date: Thu, 20 May 2021 12:38:56 +0000
Subject: note 126096 added to function.getopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-216410@lists.php.net to get a copy of this message
Unfortunately, even using Example #4 do not allow to easily detect a bad -x or --xx argument as the last -x or --xx is always “eaten” even if it is bad: If I use this (Example #4) : <?php // Script example.php $rest_index = null; $opts = getopt('a:b:', [], $rest_index); $pos_args = array_slice($argv, $rest_index); var_dump($pos_args); ?> shell> php example.php -a 1 -b 2 shell> php example.php -a 1 -b 2 --test shell> php example.php -a 1 -tb 2 All return the same result (-t and --test not defined) : array(0) { } (last one use combining single letters, making user testing much much more complicated) ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 2a01:cb08:181:ce00:483c:3309:e3c2:6096) ---- Manual Page -- https://php.net/manual/en/function.getopt.php Edit -- https://main.php.net/note/edit/126096 Del: integrated -- https://main.php.net/note/delete/126096/integrated Del: useless -- https://main.php.net/note/delete/126096/useless Del: bad code -- https://main.php.net/note/delete/126096/bad+code Del: spam -- https://main.php.net/note/delete/126096/spam Del: non-english -- https://main.php.net/note/delete/126096/non-english Del: in docs -- https://main.php.net/note/delete/126096/in+docs Del: other reasons-- https://main.php.net/note/delete/126096 Reject -- https://main.php.net/note/reject/126096 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216410) next »