Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84343 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59679 invoked from network); 5 Mar 2015 15:18:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Mar 2015 15:18:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:33141] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/83-40418-5D378F45 for ; Thu, 05 Mar 2015 10:18:45 -0500 Received: by wevl61 with SMTP id l61so16659856wev.0 for ; Thu, 05 Mar 2015 07:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=tbfI8epKnrXNPjM7PkXWaHUyelDg4Zy3/FVpFgc40Ao=; b=iTV3/aEDXD+B7l1sVqQkGX2dcQHAeYwDPYjbI5uoaU+Av0ZzV72VeCV7hgC+c1NHNz MQfNVi4E4J0lzQZeI/4IScNYfsbETj3u9YbBzIqyJZug8hajDS2Uj8H82sBGLHjqZknX ARccivkRJ7oCvGMBIqmOz0NRcKJwzv228rsyIycI5FqQ3Xc6Wpo3nxOrFhxV5erv+Gmt 9jN9XcwqyP/oVBpz143QK4cxhbR9jfDBDdShziTpC5h7wWDO8Wvd0AdFrTYqjA4iprIe 849mFKP5sdhYdwrD35W5koysGPfia3xnIlFSt70jlvUYE5kcxAX+8a+lhZMZ3hB5TktV JAYA== X-Received: by 10.181.13.146 with SMTP id ey18mr67550318wid.84.1425568721701; Thu, 05 Mar 2015 07:18:41 -0800 (PST) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id ha5sm8103088wib.1.2015.03.05.07.18.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Mar 2015 07:18:41 -0800 (PST) Message-ID: <54F87394.6080501@gmail.com> Date: Thu, 05 Mar 2015 15:17:40 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: internals@lists.php.net References: <002701d0574a$83ab4360$8b01ca20$@tutteli.ch> In-Reply-To: <002701d0574a$83ab4360$8b01ca20$@tutteli.ch> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] function signatures in XML From: rowan.collins@gmail.com (Rowan Collins) Robert Stoll wrote on 05/03/2015 13:44: > Heya, > > Does PHP store somewhere meta-information of all internal functions (and operators) in a portable format such as XML? > I would like to extract information such as > > - parameters including types > - return type > > automatically. Preferably each overload of a function but I guess that does not exist. > For instance, str_replace has overloads: > string x string x string x (&int) -> string > string x string x array x (&int) -> array > array x string x string x (&int) -> string > array x array x string x (&int) -> string > array x array x array x (&int) -> array > > Unfortunately, the manual as such is not precise enough for my needs. I'm not an expert, so can't give a final answer, but a couple of bits I've picked up from lurking for the last few months and digging into the source out of curiosity: - The manual entries for new extensions are actually built using Reflection, with a script called "docgen" here: http://svn.php.net/viewvc/phpdoc/doc-base/trunk/scripts/docgen/ - I believe the reflection in turn comes from the "ARG_INFO" macros, e.g. http://lxr.php.net/xref/PHP_TRUNK/ext/standard/basic_functions.c#2332 - The overloads you mention aren't (in most cases) really overloads, the C functions parse arguments using a bunch of macros referred to as "ZPP", and can do various things with them, including just accepting a zval (i.e. parameter of any type) and interrogating that C structure to see what type it is. For instance, str_replace does that here: http://lxr.php.net/xref/PHP_TRUNK/ext/standard/string.c#4130 - As far as I know, the return type isn't declared anywhere, it's just an output parameter which points at a zval, and the code can set it to whatever it wants. I may be missing something there though. As you can see, the arg_info just has the parameter names and by-ref flag, and in the definition itself there's just a bunch of code branches for "if (Z_TYPE_P(search) != IS_ARRAY)", "if (Z_TYPE_P(replace) != IS_STRING)", etc, so there's no way of recovering a table of valid type combinations like that without a LOT of code analysis. This is one of the things that makes consistency difficult with scalar type hinting - internal functions, although written in a strictly typed language, aren't actually type hinted! Regards, -- Rowan Collins [IMSoP]