php - 那个简单的 php 类有什么问题?
问题描述
这里出了点问题,我在发什么消息?为什么width4的输出不是4?
输出:宽度1:4 宽度2:4 宽度3:4 宽度4:20
预期:宽度1:4 宽度2:4 宽度3:4 宽度4:4
<?php
$mytest = new MyTestClass(4, 5);
echo " width4: ".$mytest->$int_width;
class MyTestClass {
public $int_width;
public $int_height;
public $int_area;
public function __construct($int_width, $int_height){
$this->my_new_test($int_width, $int_height);
echo " width3: ".$this->$int_width;
}
function my_new_test($int_width, $int_height){
$this->$int_width = $int_width;
$this->$int_height = $int_height;
echo " width1: ".$this->$int_width;
$this->$int_area = $int_width * $int_height;
echo " width2: ".$this->$int_width;
}
}
?>
解决方案
错误的
$this->$int_width
真的
$this->int_width
推荐阅读
- spring-boot - 定义过滤器时@order 无效
- java - 如何创建由完成通量触发的 Mono
- php - 如何使用正则表达式验证用户名
- c# - Xamarin - 一次插入多个 SQLite 表?
- r - 如何在 ShinyApp 的主面板中呈现 DT::data.table 和 wordcloud2::wordcloud2?
- arduino - 如何在 ESP32(Arduino) 上以编程方式查询 WiFi AP 的发射功率?
- google-data-studio - 在 DataStudio 中计算预期收入
- java - InvalidArgumentException:无效参数:用户数据目录已在使用中,
- node.js - 节点没有通过 Homebrew 下载,终端卡在这行代码上,没有更新
- bash - 如何开始在 git bash 中使用 make