Jump to content

[SOLVED] Default function parameter problem.


matthewhaworth

Recommended Posts

    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.

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?

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. >_>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.