php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79510 Accept int for $dims arg of FFI::arrayType()
Submitted: 2020-04-22 22:20 UTC Modified: 2021-09-16 21:26 UTC
From: daverandom@php.net Assigned:
Status: Open Package: FFI (PECL)
PHP Version: Next Minor Version OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daverandom@php.net
New email:
PHP Version: OS:

 

 [2020-04-22 22:20 UTC] daverandom@php.net
Description:
------------
At present, FFI::arrayType() requires that the dimensions be specified as an array of integers. For convenience, it would be nice to have it accept an integer when creating an array with a single dimension. The semantics would be identical to the logic shown below:

class FFI
{
    static function arrayType($type, $dims)
    {
        if (\is_int($dims)) {
            $dims = [$dims];
        }

        // ...
    }
}



Test script:
---------------
$int = \FFI::type('int');

var_dump(\FFI::arrayType($int, [10]));
var_dump(\FFI::arrayType($int, 10));


Expected result:
----------------
object(FFI\CType:int32_t[10])#2 (0) {
}
object(FFI\CType:int32_t[10])#3 (0) {
}

Actual result:
--------------
object(FFI\CType:int32_t[10])#2 (0) {
}
FFI::arrayType() expects parameter 2 to be array, int given in ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-16 21:25 UTC] cmb@php.net
-Package: ffi +Package: FFI
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 21:03:39 2021 UTC