|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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); } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 03:00:01 2025 UTC |
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);