Jump to content

Rectangle1.php


yrstruly

Recommended Posts

HiIm having trouble with this code:Parse error: parse error, expecting `T_FUNCTION' in C:\xampp\htdocs\exercise\Rectangle.php on line 26<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”> <head> <meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1” /> <title>Rectangle</title> </head> <body> <?php # Script 6.4 - rectangle1.php /* This page uses the Rectangle class. * This page shows a bunch of information * about a rectangle. */ // Include the class definition: require_once ('Rectangle.php'); // Define the necessary variables: $width = 42; $height = 7; // Print a little introduction: echo "<h3>With a width of $width and a height of $height...</h3>"; // Create a new object: $r = new Rectangle(); // Assign the rectangle dimensions. $r->set_size($width, $height); // Print the area. echo '<p>The area of the rectangle is ' . $r->get_area() . '</p>'; // Print the perimeter. echo '<p>The perimeter of the rectangle is ' . $r->get_perimeter() . '</p>'; // Is this a square? echo '<p>This rectangle is '; if ($r->is_square()) { echo 'also'; } else { echo 'not'; } echo ' a square.</p>'; // Delete the object: unset($r); ?> </body> </html>

Link to comment
Share on other sites

Look at the error message, it says the error is in Rectangle.php, which is an include file.You really need to start reading the error messages and trying to understand what they mean. The error message isn't even referring to this code.

Link to comment
Share on other sites

Read the error! It's telling you there is something wrong on line 26 of Rectangle.php - maybe post that?Edit: JSG beat me

Link to comment
Share on other sites

B y the way, just a curiosity question, but why are you asking these questions here at this site? Not that we mind, I guess, but most of the questions coming from this Memeber are direct copies of a set of exercises from Larry Ullman's books. There is a Forum about the Books available at the DMCI site (link here). The membership at the DMCI site are more than willing (and certainly able) to reply to these questions. And most of them (myself included) have the specific books, samples and exercises you are questioning.Just curious why you would not be using the DMCI forums?

Link to comment
Share on other sites

HiIm having trouble with this code:Parse error: parse error, expecting `T_FUNCTION' in C:\xampp\htdocs\exercise\Rectangle.php on line 26<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”> <head> <meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1” /> <title>Rectangle</title> </head> <body> <?php # Script 6.4 - rectangle1.php /* This page uses the Rectangle class. * This page shows a bunch of information * about a rectangle. */ // Include the class definition: require_once ('Rectangle.php'); // Define the necessary variables: $width = 42; $height = 7; // Print a little introduction: echo "<h3>With a width of $width and a height of $height...</h3>"; // Create a new object: $r = new Rectangle(); // Assign the rectangle dimensions. $r->set_size($width, $height); // Print the area. echo '<p>The area of the rectangle is ' . $r->get_area() . '</p>'; // Print the perimeter. echo '<p>The perimeter of the rectangle is ' . $r->get_perimeter() . '</p>'; // Is this a square? echo '<p>This rectangle is '; if ($r->is_square()) { echo 'also'; } else { echo 'not'; } echo ' a square.</p>'; // Delete the object: unset($r); ?> </body> </html>
Well i dont understand what the message is saying!
Link to comment
Share on other sites

HiParse error: parse error, expecting `T_FUNCTION' in C:\xampp\htdocs\exercise\Rectangle.php on line 26
As everyone else has stated.the first thing to do it read the errorthe error is not with the code you have posted up but within the file called Rectangle.php (taken from the error message)After locating the file then read the whole error for a second time and notice what line ! In this case 26, then use your experience of lack or to work out the problem rather than posting irrelevant code
Link to comment
Share on other sites

There are 3 important pieces of information in the error message.Parse error: parse error, expecting `T_FUNCTION' in C:\xampp\htdocs\exercise\Rectangle.php on line 26The actual error, the file, and the line number. The error is a parse error. It says there's an expected function, but a parse error just means that the code is not formed correctly. A parse error means that PHP can't even figure out how the code is structured. A parse error is different than a runtime error, where you just do something in the code that's incorrect, even though the code itself is structured correctly. This is a runtime error, for example:

$var = false;$row = mysql_fetch_assoc($var);

That code is structured correctly, but it's an error to use a value of false with mysql_fetch_assoc. That's an error that happens when the code is actually running, so that's why they call it a runtime error. A parse error happens before the code even runs, a parse error is when PHP tries to figure out the structure of the code and can't because something doesn't make sense. A parse error would be too many brackets, for example, or a missing semicolon, where PHP doesn't even know what to do.So, the first thing to get from the error message is that it's a parse error, the code is not structured correctly. The second thing is the file, it's telling you the error is in Rectangle.php, and the third is the line number, line 26. So you should look at line 26 of Rectangle.php and look for code that's not structured correctly. With a parse error, PHP detects the error on line 26, but with parse errors the actual error in the code is usually a couple lines before that, so look around lines 22-25.It's important that you be able to understand error messages if you're going to be writing code though. The error messages are the only way for PHP to tell you if there's a problem, so it's important that you try to understand what they mean.

Link to comment
Share on other sites

As everyone else has stated.the first thing to do it read the errorthe error is not with the code you have posted up but within the file called Rectangle.php (taken from the error message)After locating the file then read the whole error for a second time and notice what line ! In this case 26, then use your experience of lack or to work out the problem rather than posting irrelevant code
Morris there is no need to be cocky!
Link to comment
Share on other sites

Morris there is no need to be cocky!
Sorry Yrstruly i was just Trying to explain how the errors (even though my knowledge isn't great). I apologise as my post appeared to have came across as cocky, i was only trying to re-iterate other posts whilst trying to explain the best way to approach the problem. JustSomeGuy's explained it better and behond my knowledge.Sorry
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...