vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   iif Function - what's using for ? (https://vborg.vbsupport.ru/showthread.php?t=74611)

Dean C 01-21-2005 03:22 PM

The function is kind of redundant, the only time it helps is with clarity for new coders. I just tend to use in my scripts :)

PHP Code:

$var $arewetrue 'yes' 'no'


Brad 01-21-2005 04:19 PM

Quote:

Originally Posted by KirbyDE
No, it's a vBulletin function defined in functions.php

Heres the code for it if anyone dos'nt want to go searching.

From functions.php

PHP Code:

// ###################### Start iif #######################
function iif($expression$returntrue$returnfalse '')
{
    return (
$expression $returntrue $returnfalse);



Xenon 01-21-2005 04:36 PM

actually my editor highlights it as well, as i'm highlighting some vb functions ^^

noppid 01-21-2005 06:07 PM

iif() is handy for true and false returns. However if you use it to test and then pass data, if the data chunk is large, it may be much more inefficent then a plain old if/else.

filburt1 01-21-2005 08:17 PM

I did just notice one major problem with it, but it's the design of PHP (and most other languages) that causes it: the ternary operator supports lazy evaluation (only evaluates what is needed based on the condition), whereas the iif() function evaluates all of its arguments regardless of the condition's value.

An excerpt of my code that demonstrates the problem:
PHP Code:

function vbms_get_all_quota_usages($userids false)
{
    global 
$DB_site;
    
    
$usages = array();    
    
$extrawhere iif($userids !== false"AND userid IN (" implode(", "$userids) . ")"); 

Look at that last line. If $userids strictly equals false, it will still try to implode $userids, and of course you can't implode a non-array. The ternary operator's lazy execution doesn't try to implode $userids if it is boolean false.

noppid 01-21-2005 08:43 PM

Ah yes and here's the example I had written and realized the overhead it created just moving a copy of the data, I overlooked that it executed the addslashes() function as well even if it was not needed.

This is very inefficient, in some cases $data could have been 1MB...

PHP Code:


iif
($vbg_use_fs''addslashes($data)); 

Nice tip filburt.

deathemperor 01-22-2005 03:37 AM

as the name of the varibles vb defined, this is absolutely useful for boolean vale the best.


All times are GMT. The time now is 05:50 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02261 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete