码迷,mamicode.com
首页 > Web开发 > 详细

php类与对象简单操作

时间:2015-08-25 15:54:23      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

 1 <?php
 2 /*
 3  * Created on 2015-8-25
 4  *
 5  * To change the template for this generated file go to
 6  * Window - Preferences - PHPeclipse - PHP - Code Templates
 7  */
 8  class Type{
 9 
10     var $username;
11     public function getUserName(){
12 
13         return $this->username;
14 
15     }
16     public function setUserName($username){
17         $this->username = $username;
18 
19     }
20 
21  }
22  class Free{
23      private static $username;
24      public static function getUser(){
25          return Free::$username;
26      }
27      public static  function setUser($username){
28          Free::$username = $username;
29 
30      }
31 
32  }
33  $user = "link";
34  Free::setUser($user);
35  echo Free::getUser();
36  $type = new Type();
37  $type->setUserName("zhangming");
38  echo $type->getUserName();
39 ?>

初学php,望大家能多多纠正错误。


php类与对象简单操作

标签:

原文地址:http://www.cnblogs.com/assassin666/p/4757454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!