maddogandnoriko Posted April 3, 2009 Share Posted April 3, 2009 Can someone tell me why this is generating and unexpected tvariable error? this->languages[0] is 'en' and id is set. This function is in a class. I wanted the language to be set to languages[0] if no value was passed. And the function works if I remove:$language=$this->languages[0]. Thank you maddogandnoriko function getXML($ID,$language=$this->languages[0]){ $url= $this->URL .API.'/all/'.$language.'.xml'; $this->xml = simplexml_load_file($url); } Link to comment https://forums.phpfreaks.com/topic/152336-solved-default-value-for-function-variable/ Share on other sites More sharing options...
genericnumber1 Posted April 3, 2009 Share Posted April 3, 2009 function getXML($ID,$language = null){ if(is_null($language)) $language = $this->languages[0]; $url = $this->URL .API.'/all/'.$language.'.xml'; $this->xml = simplexml_load_file($url); } Link to comment https://forums.phpfreaks.com/topic/152336-solved-default-value-for-function-variable/#findComment-800067 Share on other sites More sharing options...
maddogandnoriko Posted April 3, 2009 Author Share Posted April 3, 2009 Can you tell me why null works? I know true and false also works...I just assumed my way would work but I was wrong. maddogandnoriko Link to comment https://forums.phpfreaks.com/topic/152336-solved-default-value-for-function-variable/#findComment-800069 Share on other sites More sharing options...
genericnumber1 Posted April 3, 2009 Share Posted April 3, 2009 Default function values can only be literals (non-variables, like a string or a number) or constants. Link to comment https://forums.phpfreaks.com/topic/152336-solved-default-value-for-function-variable/#findComment-800072 Share on other sites More sharing options...
maddogandnoriko Posted April 7, 2009 Author Share Posted April 7, 2009 literals...makes sense. Thanks for the info. maddogandnoriko Link to comment https://forums.phpfreaks.com/topic/152336-solved-default-value-for-function-variable/#findComment-803038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.