当我运行下面的代码时,我在行echo $attribute;
中出现错误错误代码:“可捕获的致命错误:类 SomeShape 的对象无法转换为字符串”:这段代码有什么问题?谢谢。
<?php
class Shape
{
static public $width;
static public $height;
}
class SomeShape extends Shape
{
public function __construct()
{
$test=self::$width * self::$height;
echo $test;
return $test;
}
}
class SomeShape1 extends Shape
{
public function __construct()
{
return self::$height * self::$width * .5;
}
}
Shape::$width=60;
Shape::$height=5;
echo Shape::$height;
$attribute = new SomeShape;
echo $attribute;
$attribute1 = new SomeShape1;
echo $attribute1;
?>