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

创建类的对象创建不了

WBOY
Release: 2016-06-06 20:21:56
Original
1401 people have browsed it

<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>
Copy after login
Copy after login

回复内容:

<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>
Copy after login
Copy after login

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

实例化后要调用方法呀

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template