Let’s say I have this array:
$meta = array(
'name' => 'John Doe',
'age' => 16,
'e-mail' => 'john.doe@doedoe.com'
);
How Do I allow users to customize the layout using those variables? (And be able to catch errors). Here’s my current idea:
extract($meta,EXTR_OVERWRITE);
$string = "Hi, I am $name. This is an $undefined_variable";
It isn’t able to catch undefined variables though.
How about this?
Or, if you could have
{{name}}, etc, directly as keys in$meta, then:Or, you could create and cache a
$metawith{{...}}keys if you can’t place them in the original one:Then, if you want to simply hide the undefined variables, by now you should have all the defined ones filled in, so anything else inside
{{..}}should be an undefined variable: