Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use arrayaccess with static class

Tags:

arrays

php

static

how I can use array access with my static class? F.e. I like to execute next script:

class A {
   ...
}
A['p'] = 15;
echo isset(A['p']) ? A['p'] : 0;
like image 367
rezo.kun Avatar asked May 21 '26 05:05

rezo.kun


2 Answers

The interface ArrayAccess only works for objects. There's nothing similar for static access.

like image 197
VolkerK Avatar answered May 22 '26 17:05

VolkerK


You can make your class a singleton class then you can access it as static class

like image 37
RoboTamer Avatar answered May 22 '26 17:05

RoboTamer