Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

TRUE or not TRUE?

Aloittaja The Wizard, helmikuu 02, 2014, 07:26:40 AP

« edellinen - seuraava »

The Wizard

Hello:

Should I be using TRUE or not using TRUE in the code below? If yes then did I writ the code correctly?

thanks

Wiz


$hooks = array(
'integrate_pre_include' => '$sourcedir/Subs-Toy_Shophooks.php', TRUE,
'integrate_actions' => 'toy_shop_add_hook', TRUE,
'integrate_admin_include' => '$sourcedir/Subs-Toy_Shophooks.php',
'integrate_admin_areas' => 'toy_shop_admin_areas'
);

$call = 'add_integration_function';

foreach ($hooks as $hook => $function)
$call($hook, $function);



Arantor

No, you didn't. This creates an array very differently to what you expected. Do a print_r on $hooks and you will find it is not at all what you expect it to be.

What you're actually after is to simplify the code:

$hooks = array(
'integrate_pre_include' => '$sourcedir/Subs-Toy_Shophooks.php',
'integrate_actions' => 'toy_shop_add_hook',
'integrate_admin_include' => '$sourcedir/Subs-Toy_Shophooks.php',
'integrate_admin_areas' => 'toy_shop_admin_areas',
);

foreach ($hooks as $hook => $function)
add_integration_function($hook, $function, true);
Holder of controversial views, all of which my own.


The Wizard

Sir Cumber-Patcher uses TRUE, and Suki says you don't have to (see WIP Toy Shop for explanation)

So who is right? Or is it one of those deals that both answers are right?

I am in no way wanting to start a fight or upset anyone I just wanted to know for future reference.

Thanks

Wiz



Arantor

I use true because I find it better to be explicit about such things. Either is fine.

Point is your original code was extremely wrong, as a print_r would have told you (since you would have 8 elements in the array, not 4, and you would have ended up assigning nonsense values in the process)
Holder of controversial views, all of which my own.


The Wizard

Thank you for the answer and the correction in my code.  :)

Advertisement: