RE: [PHP] Missing arguments for function in class? (object-orientedprogramming)

From: Date: Thu, 28 Jun 2001 17:32:27 +0000
Subject: RE: [PHP] Missing arguments for function in class? (object-orientedprogramming)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55514@lists.php.net to get a copy of this message
rename either the function or the class. class Display_Records { function display_records($row, $record_count) { $current_date = (date("Y-m-d")); $age = ($current_date); return $age; } function disp_rec($row, $record_count) { $current_date = (date("Y-m-d")); $age = ($current_date); return $age; } } $d = new Display_Records(); // no problem here print $d -> disp_rec('row', 'record cont'); // big problem here print $d -> display_records('row', 'record cont'); > -----Original Message----- > From: Thomas David Kehoe [mailto:kehoe@casafuturatech.com] > Sent: Wednesday, June 27, 2001 9:27 AM > To: php-general@lists.php.net > Subject: [PHP] Missing arguments for function in class? > (object-orientedprogramming) > > > I have a function that works perfectly (from within a script). But when I > make it a class (object) and call it from an external file, I get the > following error: > > Warning: Missing argument 1 for display_records() in > http://www.friendshipcenter.com/Objects/display_records.inc > on line 5 > > Warning: Missing argument 2 for display_records() in > http://www.friendshipcenter.com/Objects/display_records.inc > on line 5 > > After the warnings, it executes the function without passing values to the > variables (i.e., it doesn't work), and then it executes the function a > second time perfectly (with the appropriate variables). > > Line 5 is this: > > function display_records($row, $record_count) > > It displays the first error message for $row, and the second error message > for $record_count. > > I call the function with this: > > $my_records = new Display_Records; > $my_records -> display_records($row, $record_count); > > The full scripts are below. > > What I tried that didn't help was declaring the variables in the class with: > > class Display_Records { > > var $row; > var $record_count; > > I also tried setting defaults for the variables (er, attributes) with this > (it didn't help): > > $my_records = new Display_Records; > $my_records -> row = $row; > $my_records -> record_count = 1; > $my_records -> display_records($my_records -> row, $my_records -> > record_count); > > This is my first try at OOP. The code is for a personal ad website > (FriendshipCenter.com). Here's the full class script, followed by the > script I use to call the function. > -- > Thomas David Kehoe, author of > "THE EVOLUTION OF INTIMATE RELATIONSHIPS" > How Our Brains Are Hardwired For Relationships > http://www.FriendshipCenter.com/TEIR/ > > > > > > > <?php > > class Display_Records { > > function display_records($row, $record_count) { > > //Calculate age > $current_date = (date("Y-m-d")); > $birthdate = $row["BIRTHDATE"]; > $age = ($current_date - $birthdate); > > // Display record number. > echo "Row number:&nbsp;", ($record_count + $advance_row), > "<p>"; > > // Display username and e-mail address > echo "<font color=green>Username: </font>", > $row["USER_NAME"], > "<p>"; > echo "<font color=green>E-mail address: </font><a > href=mailto:", > $row["EMAIL_ADDRESS"], ">", $row["EMAIL_ADDRESS"], > "</a><p>"; > > // Display the information provided by the member. Empty fields > aren't displayed. > if ($row["DISABILITY_1" OR "DISABILITY_2" OR > "DISABILITY_3" OR > "DISABILITY_4" OR "DISABILITY_5" OR "DISABILITY_6" OR > "DISABILITY_7" OR > "DISABILITY_8"]) {echo "<font color=green>Disability, disease, or > condition: > </font>", $row[DISABILITY_1], ", ", $row[DISABILITY_2], ", ", > $row[DISABILITY_3], ", ", $row[DISABILITY_4], ", ", $row[DISABILITY_5], > ", > ", $row[DISABILITY_6], ", ", $row[DISABILITY_7], ", ", > $row[DISABILITY_8], > "<p>";} > if ($row["LIFE_STORY"]){echo "<font color=green>Life story: > </font>", $row["LIFE_STORY"], "<p>";} > if ($row["PHOTO_URL"]){echo "<IMG HEIGHT=250 SRC=", > $row["PHOTO_URL"], "><p>";} > if ($row["PHOTO_URL"]){echo "<font color=green>Photo URL: > </font><a > href=", $row["PHOTO_URL"], ">", $row["PHOTO_URL"], > "</a><p>";} > if ($row["HOMEPAGE_URL"]){echo "<font color=green>Personal website > URL: </font><a href=", $row["HOMEPAGE_URL"], ">", > $row["HOMEPAGE_URL"], > "</a><p>";} > if ($row["CITY"]){echo "<font color=green>City: > </font>", > $row["CITY"], "<p>";} > if ($row["STATE"]){echo "<font color=green>State: > </font>", > $row["STATE"], "<p>";} > if ($row["COUNTRY"]){echo "<font color=green>Country: > </font>", > $row["COUNTRY"], "<p>";} > if (($row["BIRTHDATE"]) != "0000-00-00") {echo "<font > color=green>Age: </font>", $age, "<p>";} > if ($row["GENDER"]){echo "<font color=green>Gender: > </font>", > $row["GENDER"], "<p>";} > if ($row["EDUCATION"]){echo "<font color=green>Education: > </font>", > $row["EDUCATION"], "<p>";} > if ($row["PROFESSION"]){echo "<font color=green>Profession: > </font>", $row["PROFESSION"], "<p>";} > if ($row["MARITAL_STATUS"]){echo "<font color=green>Marital > status: > </font>", $row["MARITAL_STATUS"], "<p>";} > if ($row["SEXUAL_ORIENTATION"]){echo "<font color=green>Sexual > orientation: </font>", $row["SEXUAL_ORIENTATION"], "<p>";} > if ($row["RELIGION"]){echo "<font color=green>Religion: > </font>", > $row["RELIGION"], "<p>";} > if ($row["RACE"]){echo "<font color=green>Racial or ethnic group: > </font>", $row["RACE"], "<p>";} > if ($row["HEIGHT"]){echo "<font color=green>Height: > </font>", > $row["HEIGHT"], " inches<p>";} > if ($row["WEIGHT"]){echo "<font color=green>Weight: > </font>", > $row["WEIGHT"], " pounds<p>";} > if ($row["SMOKING"]){echo "<font color=green>Smoking: > </font>", > $row["SMOKING"], "<p>";} > if ($row["DRINKING"]){echo "<font color=green>Drinking: > </font>", > $row["DRINKING"], "<p>";} > if ($row["LANGUAGE"]){echo "<font color=green>Language: > </font>", > $row["LANGUAGE"], "<p>";} > > // Display banner ad. > echo "<center><iframe > src=http://leader.linkexchange.com/1/X1258133/showiframe? > width=468 > height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 > scrolling=no><a > href=http://leader.linkexchange.com/1/X1258133/clickle > target=_top><img width=468 height=60 border=0 ismap > src= >http://leader.linkexchange.com/1/X1258133/showle?></a></iframe><br><a > href=http://leader.linkexchange.com/1/X1258133/clicklogo > target=_top><img > src=http://leader.linkexchange.com/1/X1258133/showlogo? > width=468 height=16 > border=0 ismap></a><br></center>"; > } > } > > ?> > > > -- > > > > // This loop executes to display each record. > do { > > // Uses class for displaying records > $my_records = new Display_Records; > $my_records -> display_records($row, $record_count); > > // You've displayed one more record, so increment the record number. > ++$record_count; > > // Repeat the above loop while there is at least one more record, for a > maximum of 20 records. > } while( ($row = mysql_fetch_array($selectresult)) && ($record_count <= > 20) ); > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#55514) next »