php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60572 Can't make a optional callback arguments in extension
Submitted: 2011-12-20 09:52 UTC Modified: 2011-12-20 13:51 UTC
From: laruence@php.net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.8 OS:
Private report: No CVE-ID: None
 [2011-12-20 09:52 UTC] laruence@php.net
Description:
------------
following codes in extension didn't work as expected:
....
 zend_fcall_info fci = {0};
 zend_fcall_info_cache fci_cache;
...
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|f", &key, &klen, 
&fci, &fci_cache) {
         return;
     }

    if (!fci.size) {   
       // not a valid callback
    }


in PHP script:

php_ext_function("name", NULL);  

result in:
argument 2 not a valid callback...  

I haved tried set the arginfo with all_null.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-20 13:17 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2011-12-20 13:17 UTC] cataphract@php.net
Optional means "accepting the argument was not given", not "accepting a NULL". To accept NULLs, you have to use !, otherwise the argument is coerced to whatever type you're expecting, which is not possible here.

so

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|f!", &key, &klen, 
&fci, &fci_cache) {
 [2011-12-20 13:51 UTC] laruence@php.net
ah, thanks cataphract.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC