I did not care any notices from php in a long times as a php developer . but themeforest require so I must find a simple way to solve the notices.
My suggest is build a function that will not echo “un-isset” var. something like this
function prevent_notice($var){
if(isset($var)){
echo $var;
}
}
so you can ignore any notices from any un-isset var without set init them.The issue is if I want to prevent notice of an var like $user[‘name’] , then php will notice that the offset ‘name’ must created!
So anyone can know how to know array and key of $var when we use an var like $user[‘name’] inside an function.
Thanks!
- Most Wanted Bounty Winner
- Sold between 250 000 and 1 000 000 dollars
- Has been a member for 5-6 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Won a Competition
- Bought between 100 and 499 items
- Exclusive Author
- Referred between 200 and 499 users
LOL!!! 
Notices are there for you to kill them, not to hide them. Just fix the errors! 
- Sold between 100 000 and 250 000 dollars
- Won a Competition
- Author was Featured
- Item was Featured
- Referred between 500 and 999 users
- Author had a Free File of the Month
- Author had a File in an Envato Bundle
- Bought between 10 and 49 items
rongcon saidinefficient due the extra function call.
function prevent_notice($var){ if(isset($var)){ echo $var; } }
BF
pixelentity saidwhy not? I just call them in theme options. which only use once. it’s simple the code.
rongcon saidinefficient due the extra function call. BF
function prevent_notice($var){ if(isset($var)){ echo $var; } }
normal way (which I know)
- set init data for var
- echo var
better way
- declare prevent_notice function
- call function
so we can ignore a large init vars code lines.
let me know better way?
RubenBristian said
LOL!!!Notices are there for you to kill them, not to hide them. Just fix the errors!
![]()
no I did not try to hide them. I just checked to see if it’s empty then hide it instead echo it.
. to prevent themeforest’s notices 
//prevent notice when the var is not set
function prevent_notice($var,$key = ""){
if($key){
if(isset($var[$key]) and array_key_exists($key,$var)){
echo $var[$key];
}
}else{
if(isset($var)){
echo $var;
}
}
}
examples single var//normal echo $main_option['logo_url']; //use function prevent_notice($main_option['logo_url']);example var from array
//normal echo $checkbox_responsive[1]; //function prevent_notice($checkbox_responsive,1)the profit of this function that you will never need to init any data before echo it. which is very popular and a big problem in theme options. I wanna to keep my code clear. no more waste code lines for init vars.

- Most Wanted Bounty Winner
- Sold between 250 000 and 1 000 000 dollars
- Has been a member for 5-6 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Won a Competition
- Bought between 100 and 499 items
- Exclusive Author
- Referred between 200 and 499 users
rongcon said
//normal echo $main_option['logo_url']; //use function prevent_notice($main_option['logo_url']);
Couldn’t you just do:
echo isset($main_option['logo_url']) ? $main_option['logo_url'] : 'default_logo_here';
Because if you are giving the option of a logo here, you should definitely provide an alternative. It isn’t a good practice to leave the user without a logo if he doesn’t set it.. This should be the case for all theme options.
- Sold between 100 000 and 250 000 dollars
- Won a Competition
- Author was Featured
- Item was Featured
- Referred between 500 and 999 users
- Author had a Free File of the Month
- Author had a File in an Envato Bundle
- Bought between 10 and 49 items
rongcon saiddone few times the overhead is negligible so it really doesn’t matter but, if it’s all around in your code, including nested loops, you may want to avoid unnecessary functions call and use directly
why not? I just call them in theme options. which only use once. it’s simple the code.
if (isset($var)) echo $var;
RubenBristian saidthanks for your code. if the option alway have real init so I never care for notice problem
rongcon said
//normal echo $main_option['logo_url']; //use function prevent_notice($main_option['logo_url']);Couldn’t you just do:
echo isset($main_option['logo_url']) ? $main_option['logo_url'] : 'default_logo_here';Because if you are giving the option of a logo here, you should definitely provide an alternative. It isn’t a good practice to leave the user without a logo if he doesn’t set it.. This should be the case for all theme options.
. because I’m alway set init for it , so the notice’s never come. I just don’t happy with init value for empty var 
$var = "";
- Sold between 100 000 and 250 000 dollars
- Won a Competition
- Author was Featured
- Item was Featured
- Referred between 500 and 999 users
- Author had a Free File of the Month
- Author had a File in an Envato Bundle
- Bought between 10 and 49 items
Honestly, for theme options, we just set default values once. A very simple way to do it by using http://codex.wordpress.org/Function_Reference/shortcode_atts
$options = shortcode_adds($defaults,$options)
