php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60593 Please support binary and set in spl types
Submitted: 2011-12-22 15:24 UTC Modified: 2017-01-10 08:15 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jueljust at gmail dot com Assigned:
Status: Suspended Package: SPL_Types (PECL)
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
21 + 29 = ?
Subscribe to this entry?

 
 [2011-12-22 15:24 UTC] jueljust at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/book.spl-types
---

$binary = (binary) 'abcde12345';

Class PermissionSet extends SplSet{
    const __default = 0;

    const OwnerRead = pow(2,0);
    const OwnerWrite = pow(2,1);
    const OwnerExcute = pow(2,2);
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-01 19:06 UTC] clicky at erebot dot net
Not really sure what the example is supposed to do: you can't use expressions (like pow(x,y)) with the const keyword. You may only use constant values in that context.

Aside from that remark, pease note that PHP 5.4 introduced support for binary numbers notation.
So your example could be rewritten as:

class PermissionSet extends SplSet
{
    class __default = 0;

    const OwnerRead = 0b100;
    const OwnerWrite = 0b10;
    const OwnerExecute = 0b1;
}

Then again, I suppose you'd want to be able to do something like:
$ownerPerm = PermissionSet(PermissionSet::OwnerRead | PermissionSet::OwnerWrite);

Unfortunately, this is not possible due to the way the SPL_Types extension works. SplSet only works with the constants defined in the class, so you'd have to define all possible combinations as constants:

class PermissionSet extends SplSet
{
    class __default = 0;

    const OwnerRead = 0b100;
    const OwnerWrite = 0b010;
    const OwnerExecute = 0b001;

    const NoRights = 0b000;
    const __RW = 0b110;
    const __RX = 0b101;
    const __WX = 0b011;
    const __RWX = 0b111;
}

Then you can combine the values together provided the result matches the value of a constant of the class.

$ownerPerm = PermissionSet(PermissionSet::OwnerRead | PermissionSet::OwnerWrite);
// same as:
$ownerPerm = PermissionSet(PermissionSet::__RW);
 [2017-01-10 08:15 UTC] kalle@php.net
-Status: Open +Status: Suspended
 [2017-01-10 08:15 UTC] kalle@php.net
Suspending this report as the extension have not had a release for almost 5 years.  Please revive this if the extension once again shows life
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC