Jump to content

To Define A Class


yrstruly
 Share

Recommended Posts

HalloI have the following code and it gives me an error message:Parse error: parse error, expecting `T_FUNCTION' in C:\xampp\htdocs\exercise\HelloWorld.php on line 13I've tried sto corret the script , but i cant find the problem.<?php # Script 6.1 - HelloWorld.php /* This page defines the HelloWorldclass.4 * The class says "Hello, world!" indifferent languages.5 */ class HelloWorld { // This method prints a greeting. // It takes one argument: the language to use. // Default language is English. function say_hello ($language ='English') { // Put the greeting withinP tags. echo '<p>'; // Print a message specific to alanguage. switch ($language) { case 'Dutch': echo 'Hello, wereld!'; break; case 'French': echo 'Bonjour, monde!'; break; case 'German': echo 'Hallo, Welt!'; break; case 'Italian': echo 'Ciao, mondo!'; break; case 'Spanish': echo '¡Hola, mundo!'; break; case 'English': default: echo 'Hello, world!'; break; } // End of switch. // Close the HTML paragraph. echo '</p>'; } // End of say_hello() function. } // End of HelloWorld class. ?>

Link to comment
Share on other sites

There are a lot of line breaks where there shouldn't be. For example, this is supposed to be a single-line comment:// It takes one argument: thelanguage to use.Instead, it's a comment on one line, and a syntax error on the next, because of the line break. A lot of the comments have a line break in the middle of them like that, fix those first and see if that solves the issue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...