Re: CodeGen_PECL int pass-by-reference

From: Date: Mon, 19 Nov 2007 12:02:45 +0000
Subject: Re: CodeGen_PECL int pass-by-reference
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-4927@lists.php.net to get a copy of this message
Matt Williamson wrote:
Where the return value is an error code, and the ncidp parameter is overwritten with the filehandle number of the opened file. But I can't figure out how to construct a <proto> and <code> block that will make this work. E.g.: <function name="nc_open"> <proto> int nc_open(string path, int omode, resource nc_filehandle &amp;ncidp) </proto>
The prototype above should produce an error, the only types for which pass-by-reference is implemented right now are "array" and "mixed", both mapping to a zval internally. There seems to be some problem in the current proto parser though as it will always complain about only 'array' and 'mixed' arguments may be passed by reference, 'foo' is of type 'char' in foo.xml on line ... so it is always seeing a "char" type parameter instead of the real type in the proto and so it all fails right now. Once i've got this fixed (see also http://pear.php.net/bugs/8621) it should work like this: To return a value by reference you should be able to use "mixed" like this: <function name="mixed_by_ref"> <proto>void mixed_by_ref(mixed &amp;foo)</proto> <code> convert_to_double(foo); Z_DVAL_P(foo) = 3.14; </code> <test> <code>$f = 42; mixed_by_ref($f); echo $f;</code> <result>3.14</result> </test> </function> This converts the variable bound to the "foo" parameter to type double and assigns a new value to it. For PHP "int" instead of "float" results you would use "convert_to_long()" and "Z_LVAL_P()" instead. -- Hartmut Holzgraefe, Principal Support Engineer . Discover new MySQL Monitoring & Advisory features at: http://www.mysql.com/products/enterprise/whats_new.html Hauptsitz: MySQL GmbH, Dachauer Str.37, 80335 München Geschäftsführer: Kaj Arnö - HRB München 162140

« previous php.pecl.dev (#4927) next »