Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Resource authorization

Determine whether an authenticated actor may perform a specific action on a particular record.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

function mayEdit(int $actor, array $permissions, int $owner): bool

Determine whether an authenticated actor may perform a specific action on a particular record. Derive identity and roles from trusted server-side state, then evaluate ownership or a named permission. Strict comparisons avoid type coercion. Missing permission and mismatched ownership should produce a denial before any update. The === comparison examines values already received by the function. A non-strict caller may first coerce the string "4" to the integer 4.

function mayEdit(int $actor,array $permissions,int $owner):bool{return $actor===$owner || in_array("edit:any",$permissions,true);}
echo json_encode([mayEdit(4,[],4),mayEdit(4,[],9),mayEdit(4,["edit:any"],9)]);
echo "\n",json_encode(mayEdit("4",[],4));
[true,false,true]
true

Examples

<?php
function mayEdit(int $actor,array $permissions,int $owner):bool{return $actor===$owner || in_array("edit:any",$permissions,true);}
echo json_encode([mayEdit(4,[],4),mayEdit(4,[],9),mayEdit(4,["edit:any"],9)]);
echo "\n",json_encode(mayEdit("4",[],4));

Result

[true,false,true]
true

Sources