First time I've built a class, but IDE is throwing up a syntax error; not shown when functions/variables are extracted from class?

Finally, I'm getting into OOP and attempting to put together my first class. However, my IDE (NetBeans) throws up an error on the last function's (sanitize()) closing parentheses. This doesn't happen when all the class contents are extracted from the class.

Here's my code:

class db_class {

    $error_log = false; 

    function connect($db_host, $db_user, $db_pass) {
        $connect = mysql_connect($db_host, $db_user, $db_pass);
        return $connect;

    function select_db($db_database) {
        $select_db = mysql_select_db($db_database);
        return $select_db;

    function array_prepare($data) {
        $size = sizeof($array);

        foreach($array as $k => $v) {
        $keys[] = $k;

        $size_md = sizeof($array[$keys[0]]);
        for($i = 0; $i < $size_md; $i++) {
            $value .= '(';
            for($j = 0; $j < $size; $j++) {
                    $value .= "'".$array[$keys[$j]][$i]."',";
            $value = rtrim($value, ',');
            $value .= '), ';
        $value = rtrim($value, ',');

        return $value;

    function sanitize($data) {
        foreach($data as $k => $v) 
            $data[$k] = sanitize($v); //recursive
            $data = mysql_real_escape_string($data);
        return $data;
    } // <- where the error is thrown up  


I really don't see what I've done wrong, and the suggestions offered by NetBeans are many (it offers like 10 explanations for the syntax error). Can anyone pick up what could be causing this issue?

Any help would be greatly appreciated!


You're missing a visibility declaration on your property.

In other answers they have you use var, however I would advise you to use PHP5 visibility declarations; public, protected or private. The visibility of the variable should be based on the need for that piece of data. As a general rule though, you should limit the amount of properties that are declared public. Ultimately, you have no control over the data that can be assigned to a public property.

Furthermore, you should put a visibility declaration on your functions as well. Not having any visibility declaration will mark them as public, this is probably not what you'll want for all functions in a class.

Need Your Help

Project looking in wrong directory for files(streams)

c# xna stream directory

I've been building a game for the past couple of days. After i've reached certain milestones i'll C&amp;P the project folder into my dropbox folder then create a new one in my visual studio folder....

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.