Home >Backend Development >PHP Tutorial >创建类的对象创建不了

创建类的对象创建不了

WBOY
WBOYOriginal
2016-06-06 20:21:561420browse

<code><?php class shape
{
 var $x,$y,$r;
 function add($x,$y,$r)
 {
 $image=imagecreate(500,300);
 $background=imagecolorallocate($image,255, 255,255);
 $red=imagecolorallocate($image,255,0, 0);
 imagearc($image, $x, $y, $r, $r, 0,360,$red);
 header("Content-type:image/gif");
 imagegif($image);
 
 $obj->x='100';
$obj->y='100';
$obj->r='50';
echo $obj->x, $obj->y, $obj->r;
 
 
 }
}
$obj=new shape;

?></code>

回复内容:

<code><?php class shape
{
 var $x,$y,$r;
 function add($x,$y,$r)
 {
 $image=imagecreate(500,300);
 $background=imagecolorallocate($image,255, 255,255);
 $red=imagecolorallocate($image,255,0, 0);
 imagearc($image, $x, $y, $r, $r, 0,360,$red);
 header("Content-type:image/gif");
 imagegif($image);
 
 $obj->x='100';
$obj->y='100';
$obj->r='50';
echo $obj->x, $obj->y, $obj->r;
 
 
 }
}
$obj=new shape;

?></code>

我运行了,是可以的,只不过你的代码写得让我很蛋痛

实例化后要调用方法呀

我猜你是因为缺少了GD库导致的,去安装一下吧

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn