Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

{$_GET['action']}(); What does mean all these braces?

Tags:

php

braces

Could someone please help to understand this syntaxe trick in php:

enter $controller->{$_GET['action']}();

I'm talking about the

{$_GET['action']}();

I'm trying to understand the mvc pattern on this blog http://r.je/mvc-in-php.html but it's realy help my if I could understand this syntax trick...

Thanks

like image 337
user2970464 Avatar asked Nov 21 '25 11:11

user2970464


1 Answers

It's a way to dynamically access a member of an object.

$key = 'test';
$object->{$key}

Is equivalent to:

$object->test

In your example, someone is running whatever method specified by $_GET['action'] (which is the action variable in the querystring) on the $controller.

See variable variables and variable functions in the manual.

like image 165
Brad Avatar answered Nov 24 '25 03:11

Brad