[英]What's wrong with the last line of my code?
The following code is for my University project. 以下代码适用于我的大学项目。 The last line has an error when I run as a web page ... I need help on how to solve this issue.
当我作为网页运行时,最后一行有错误...我需要有关如何解决此问题的帮助。
<?php
include_once 'ShapeClass.php';
class Square extends Shape
print "<h2>This square's side is not bigger than the parallelogram's height</h2>";
}
break;
}
?>
The right way.. 正确的方式..
<?php
include_once 'ShapeClass.php';
class Square extends Shape
{
function __construct()
{
print("<h2>This square's side is not bigger than the parallelogram's height</h2>");
}
}
break
statement. break
声明。 print
as it is inside the class. print
。 You need to wrap that in a method. {
after your class
class
后忘记打开{
Try this, 尝试这个,
class Square extends Shape {
function __construct() {
print "<h2>This square's side is not bigger than the parallelogram's height</h2>";
}
}
?>
You might want to check the braces in your code, it looks quite haphazard. 您可能要检查代码中的花括号,这看起来很随意。
include_once 'ShapeClass.php';
class Square extends Shape
{
print "<h2>This square's side is not bigger than the parallelogram's height</h2>";
break;
}
?>
There are many things wrong with this. 这有很多问题。 First, a class code block is in the form
首先,类代码块的形式为
class MyClass extends OtherClass {
// code for MyClass goes here
}
You don't even have an opening curly brace. 您甚至都没有花括号。
Second, there should not be arbitrary code placed inside of a class. 其次,在类内部不应放置任意代码。 Thus, the
print_r()
should not be placed directly inside the curly braces. 因此,不应将
print_r()
直接放在花括号内。
Third, if you are trying to stop execution, the break
is incorrect in context. 第三,如果您试图停止执行,则
break
在上下文中是不正确的。 Since it is also arbitrary code, it should not be placed directly inside the curly braces. 由于它也是任意代码,因此不应将其直接放在花括号内。 Also, it should probably be
exit()
. 另外,它可能应该是
exit()
。
I suggest reading 3 chapters on object oriented programming from Larry Ullman's book, http://www.larryullman.com/books/php-advanced-and-object-oriented-programming/ . 我建议阅读拉里·乌尔曼(Larry Ullman)的书( http://www.larryullman.com/books/php-advanced-and-object-oriented-programming/)中有关面向对象编程的3章。 Also, you might consider reading up on the fundamentals of object oriented php http://au2.php.net/oop5.basic .
另外,您可以考虑阅读面向对象的php http://au2.php.net/oop5.basic的基础知识。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.