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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jueljust at gmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Mar 29 13:01:29 2024 UTC