Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: The Wizard - helmikuu 02, 2014, 07:26:40 AP

Otsikko: TRUE or not TRUE?
Kirjoitti: The Wizard - helmikuu 02, 2014, 07:26:40 AP
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);


Otsikko: Re: TRUE or not TRUE?
Kirjoitti: Arantor - helmikuu 02, 2014, 03:56:15 IP
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);
Otsikko: Re: TRUE or not TRUE?
Kirjoitti: The Wizard - helmikuu 02, 2014, 04:07:10 IP
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


Otsikko: Re: TRUE or not TRUE?
Kirjoitti: Arantor - helmikuu 02, 2014, 04:21:16 IP
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)
Otsikko: Re: TRUE or not TRUE?
Kirjoitti: The Wizard - helmikuu 02, 2014, 05:25:52 IP
Thank you for the answer and the correction in my code.  :)