相关疑难解决方法(0)

语法'%s'和'%d'是什么意思作为调用变量的简写?

在这个例子中'%s'和'%d'是什么意思?它似乎是调用变量的简写.这种语法只能在一个类中使用吗?

// Class
class Building {
    // Object variables/properties
    private $number_of_floors = 5; // These buildings have 5 floors
    private $color;

    // Class constructor
    public function __construct($paint) {
        $this->color = $paint;
    }

    public function describe() {
        printf('This building has %d floors. It is %s in color.', 
            $this->number_of_floors, 
            $this->color
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:令我困惑的部分是编译器如何知道%d指的是哪个变量?它是否按照成员变量的声明顺序排列?

php oop

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

oop ×1

php ×1