PHP--> Created a class, but assigning values to the properties fail

I'm creating a class and attempting to use it. However, the values I set are not being retained. Please advise!

Here's my class definition:

class MemberData
var $mdId;
var $mdFname;
var $mdLname;
var $mdEmail;
var $mdTwitter;
var $mdFacebook;
var $mdMyspace;
var $mdPhoneNumber;
var $mdNotes;

function MemberData($mdId, $mdFname, $mdLname, $mdEmail, $mdTwitter, $mdFacebook, $mdMyspace, $mdPhoneNumber, $mdNotes)
        $this->mdId = $mdId;
        $this->mdFname = $mdFname;
        $this->mdLname = $mdLname;
        $this->mdEmail = $mdEmail;
        $this->mdTwitter = $mdTwitter;
        $this->mdFacebook = $mdFacebook;
        $this->mdMyspace = $mdMyspace;
        $this->mdPhoneNumber = $mdPhoneNumber;
        $this->mdNotes = $mdNotes;

}//end function

}//end MemberData class

Here's where I instantiate the class and attempt to set and print one of the property values:



$listMember = new MemberData();

echo "herexy";

$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";

        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";

                        case 0: $listMember->mdFname=$data[$c];break;
                        //case 0: $listMember->mdFname["blue"];break;
                        case 0: break;
                        //case 1: $listMember->mdLname($data[$c]);break;
                        case 2: echo "c==$c<br>";break;
                        case 3: echo "c==$c<br>";break;
                        case 4: echo "c==$c<br>";break;
                        case 5: echo "c==$c<br>";break;

                }//end switch
        print "listmember->mdFname == $listmember->mdFname";
    }//end while


You have two case 0 statements. I don't use switch statements very often but I'm pretty sure that's not the way switch statements are supposed to be used.

I would rewrite your switch to look something like this:

switch ($c) {
    case 0:
        echo "c==$c<br>";

Otherwise, your values aren't being assigned because you aren't passing anything to the parameters of the constructor. You would need to assign values when you create the object:

$listMember = new MemberData($arg1, $arg2, ...);.

Right now the only property that should be set is mdFname and only when $c is equal to 0. However, with 2 case 0: statements I'm not sure what the interpreter do here and may very well not assign the property any value.

Should read about classes and objects with PHP 5.

Need Your Help

Mootools Shift-Tab Event Problem

javascript events mootools

Im using the most recent moo release and trying to write a function that evaluates the user given expression on event "keyup". As soon as my test's are passing I put the focus on the next input ele...

Regex to replace a repeating string pattern

java regex string pattern-matching replaceall

I need to replace a repeated pattern within a word with each basic construct unit. For example

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.