matthewhaworth Posted July 10, 2008 Share Posted July 10, 2008 function numrows($qry = $this->_tempquery) { return $qry->num_rows; } Parse error: syntax error, unexpected T_VARIABLE in C:\apache2triad\htdocs\forum\db.class.php on line 30 Line 30 is the first line in the code I have shown you. I have looked behind it and there are definitely no missing ';'. I think the problem is setting a variable as the default parameter.. maybe it has to be $qry = "..", but I'll be really annoyed if it does, because it messes up my whole script concept. Quote Link to comment https://forums.phpfreaks.com/topic/114141-solved-default-function-parameter-problem/ Share on other sites More sharing options...
wildteen88 Posted July 10, 2008 Share Posted July 10, 2008 You cannot use a variable to set a functions default parameter value. What I'd is this function myfunc($var = null) { if(is_null($var)) { $var = $my_default_var; } } Quote Link to comment https://forums.phpfreaks.com/topic/114141-solved-default-function-parameter-problem/#findComment-586682 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Yeah, wildteen88's code would certainly work. Read up on default function values in the PHP manual for any clarification you need. @_@ It would make life easier if you could just do it the way you have it though. =P Quote Link to comment https://forums.phpfreaks.com/topic/114141-solved-default-function-parameter-problem/#findComment-586685 Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 Yeah, wildteen88's code would certainly work. Read up on default function values in the PHP manual for any clarification you need. @_@ It would make life easier if you could just do it the way you have it though. =P I don't quite understand what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/114141-solved-default-function-parameter-problem/#findComment-586689 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 The code that wildteen88 posted will do what you want. PHP doesn't allow function defaults to be set to any variable, so you need to see if it has the default NULL value, and if it does, then set it to the "default" you want. I was telling you to look it up in the PHP manual if you had any other questions, because there are most certainly some comments on the page that could be of use. And I was also saying that life would be a bit easier if you could assign class properties to a function's default value in the function header. >_> Quote Link to comment https://forums.phpfreaks.com/topic/114141-solved-default-function-parameter-problem/#findComment-586692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.