Trouble referencing variables inside hive using \F3:: call

45 views
Skip to first unread message

SoftWord

unread,
Aug 2, 2018, 3:52:09 AM8/2/18
to f3-fra...@googlegroups.com

In this example I can't change the array USERROLES inside the hive by reference:

\F3::set('USERROLES', array());
$a = &\F3::ref('USERROLES');

$a[$permissionName] = $value;


Using \Base:instance() it works:

$f3 = \Base::instance();

$f3->set('USERROLES', array());
$a = &$f3->ref('USERROLES');

$a[$permissionName] = $value;


but.......why?

ikkez

unread,
Aug 2, 2018, 4:56:05 AM8/2/18
to Fat-Free Framework
Hi. Probably because the F3:: static calls are just forwarded by a simple magic call wrapper and that does not take references into account.
NB: this F3::set thing is just to keep legacy code support.. I don't think this is patched, it's more likely to be deprecated and removed, so I'd suggest you use
\Base:instance() instead ;)

SoftWord

unread,
Aug 2, 2018, 4:59:04 AM8/2/18
to Fat-Free Framework
Fast support as usually ikkez ^^, I'm back after 2 years of stop work and I'm very happy to turn back to use F3 ^^

Ok, I'v read something about "legacy support" comment inside f3.php file:

//! Legacy mode enabler
class F3 {

It's ok for me to use \Base::instance() method.

And what about declare: "global $f3;" inside functions() ? it's same as Base::instance ?

Rayne

unread,
Aug 3, 2018, 4:19:28 PM8/3/18
to f3-fra...@googlegroups.com
Base::instance() always returns the same instance. You could declare are global variable if you absolutely want to.

SoftWord

unread,
Aug 7, 2018, 4:08:58 AM8/7/18
to Fat-Free Framework
Thanks :)
Reply all
Reply to author
Forward
0 new messages