Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93627 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25700 invoked from network); 29 May 2016 18:58:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 May 2016 18:58:10 -0000 Authentication-Results: pb1.pair.com header.from=as@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=saponara@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.49 as permitted sender) X-PHP-List-Original-Sender: saponara@gmail.com X-Host-Fingerprint: 209.85.213.49 mail-vk0-f49.google.com Received: from [209.85.213.49] ([209.85.213.49:33585] helo=mail-vk0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/04-23584-0CB3B475 for ; Sun, 29 May 2016 14:58:09 -0400 Received: by mail-vk0-f49.google.com with SMTP id r140so200433960vkf.0 for ; Sun, 29 May 2016 11:58:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=rWZTO5jd1XP0sWkUNesi8HTtDgDLthpX15lmiJQixzQ=; b=BnvMaagnTKexDC6037Q/IOlE5emEV4DMuMG/IURyMYhcVWel0Ep7HSSma6OAyV53e6 lptsVFN9wIKUd/wUMD6Dsf8LzaS2XBQS2LX1cuUJAqP6TbFxZ0FrM5Rvi2jkOOi7nka+ elvqOAi2j7i34PukK9aK6TW31oBx6uK2R2cPjZFOIuMk5lSKMV2P5Am1nlM/edlH/5LJ uKaWGt/faITfmnPzSvK76MldPdfn+9Awb2hAv63iQZeHFaVc6coEPrzw5YmIowOiWMA0 xmh0HubulzJiEA0CE4yoy6bqsZyClKwD1ruoOlx2JGrQO6vki2jS+1ORi0MlzsCfwqfY EHuQ== X-Gm-Message-State: ALyK8tKVub7PosxsimDgnMiWaxzBSgizrDfD5ZKv+xYV2zV8rAwGQcWTcOT+5KQxRlgmHQ== X-Received: by 10.159.40.37 with SMTP id c34mr11719878uac.89.1464548286393; Sun, 29 May 2016 11:58:06 -0700 (PDT) Received: from mail-vk0-f46.google.com (mail-vk0-f46.google.com. [209.85.213.46]) by smtp.gmail.com with ESMTPSA id 36sm4777525uas.23.2016.05.29.11.58.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 May 2016 11:58:06 -0700 (PDT) Received: by mail-vk0-f46.google.com with SMTP id d127so40231588vkh.2 for ; Sun, 29 May 2016 11:58:06 -0700 (PDT) X-Received: by 10.159.55.132 with SMTP id q4mr11287367uaq.56.1464548285867; Sun, 29 May 2016 11:58:05 -0700 (PDT) MIME-Version: 1.0 Reply-To: as@php.net Received: by 10.103.79.216 with HTTP; Sun, 29 May 2016 11:57:46 -0700 (PDT) Date: Sun, 29 May 2016 14:57:46 -0400 X-Gmail-Original-Message-ID: Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: [RFC] Add &$optind to getopt From: as@php.net Hello all, Many getopt implementations expose an `optind` variable to userland which contains the last argv index examined by the option parser. This is useful when mixing flag arguments with positional arguments, as it makes locating the positional arguments easy. For example, in C and Bash... ./test -a 1 -b 2 file1 file2 After option parsing finishes, `optind` is 5 ("file1"). PHP's getopt implementation already uses an `optind` variable under the hood. I propose exposing this value via an optional by-ref param on `getopt`. It would look like this: # php test.php -a 1 -b 2 file1 file2 $optind = null; getopt('a:b:', [], $optind); var_dump($optind); // int(5) I'm hoping to gather feedback on this idea before submitting an RFC. Patch is here: https://github.com/php/php-src/compare/master...adsr:getopt-optind Thanks, Adam