hrefspace

 找回密码
 立即注册
搜索
热搜: PHP PS 程序设计
查看: 1245|回复: 0

构造方法

[复制链接]

921

主题

1132

帖子

3571

积分

超级版主

Rank: 8Rank: 8

积分
3571

论坛头条论坛元老谋士数据帝优秀版主超级版主见习版主论坛版主

发表于 2023-2-12 13:19:26 | 显示全部楼层 |阅读模式
构造方法


<style type="text/css">
<!--
body,td,th {
    font-size: 12px;
}
body {
    margin-left: 10px;
        margin-top: 10px;
        margin-right: 10px;
        margin-bottom: 10px;
}
-->
</style>



<?php
        class MyObject{
                public $object_name;
                public $object_price;
                public $object_num;
                public $object_agio;
                function __construct($name,$price,$num,$agio){
                    $this -> object_name = $name;
                        $this -> object_price = $price;
                        $this -> object_num = $num;
                        $this -> object_agio = $agio;
                }
                function setObjectName($name){
                    $this -> objecct_name = $name;
                }
                function getObjectName(){
                    return $this -> object_name;
                }
        }
        $c_book = new MyObject('Western-style clothes',1500,5,8);
        echo $c_book -> getObjectName();
?>



执行结果:
Western-style clothes

世界上最遥远的距离,不是生与死的距离,而是我站在你面前,你却不知道我爱你
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|hrefspace

GMT+8, 2024-4-29 20:19 , Processed in 0.058902 second(s), 22 queries .

Powered by hrefspace X3.4 Licensed

Copyright © 2022, hrefspace.

快速回复 返回顶部 返回列表