Int在CentOS 7.1和Laravel 5.1的PHP中作为字符串处理
我在Windows系统上开发并使用Int在CentOS 7.1和Laravel 5.1的PHP中作为字符串处理,php,mysql,laravel,unix,centos,Php,Mysql,Laravel,Unix,Centos,我在Windows系统上开发并使用==进行大量比较,以确保值和类型都符合预期。我只是在这方面遇到了问题(比较失败),并且刚刚发现int类型的值(在mysql中)是作为字符串处理的 在Windows上,它看起来像这样: Order {#488 ▼ #table: "orders" #guarded: array:1 [▶] #hidden: [] #fillable: array:9 [▶] #dates: array:1 [▶] #connection: null #
==代码>进行大量比较,以确保值和类型都符合预期。我只是在这方面遇到了问题(比较失败),并且刚刚发现int类型的值(在mysql中)是作为字符串处理的
在Windows上,它看起来像这样:
Order {#488 ▼
#table: "orders"
#guarded: array:1 [▶]
#hidden: []
#fillable: array:9 [▶]
#dates: array:1 [▶]
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:14 [▼
"id" => 6
"currency_id" => 1
"user_id" => 1
"coupon_id" => 1
"status" => 2
"created_at" => "2017-06-26 00:37:44"
"updated_at" => "2017-06-26 00:37:50"
"deleted_at" => null
]
Order {#488 ▼
#table: "orders"
#guarded: array:1 [▶]
#hidden: []
#fillable: array:9 [▶]
#dates: array:1 [▶]
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:14 [▼
"id" => "6"
"currency_id" => "1"
"user_id" => "1"
"coupon_id" => "1"
"status" => "2"
"created_at" => "2017-06-26 00:37:44"
"updated_at" => "2017-06-26 00:37:50"
"deleted_at" => null
]
在CentOS,就像这样:
Order {#488 ▼
#table: "orders"
#guarded: array:1 [▶]
#hidden: []
#fillable: array:9 [▶]
#dates: array:1 [▶]
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:14 [▼
"id" => 6
"currency_id" => 1
"user_id" => 1
"coupon_id" => 1
"status" => 2
"created_at" => "2017-06-26 00:37:44"
"updated_at" => "2017-06-26 00:37:50"
"deleted_at" => null
]
Order {#488 ▼
#table: "orders"
#guarded: array:1 [▶]
#hidden: []
#fillable: array:9 [▶]
#dates: array:1 [▶]
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:14 [▼
"id" => "6"
"currency_id" => "1"
"user_id" => "1"
"coupon_id" => "1"
"status" => "2"
"created_at" => "2017-06-26 00:37:44"
"updated_at" => "2017-06-26 00:37:50"
"deleted_at" => null
]
我真的不知道是什么原因造成的。请让我知道什么额外的信息将需要找到这一点。因为我一点也不知道,所以我不知道到底什么是相关的
其他信息:
我使用的是Laravel 5.1,并使用Laravel的dd()
方法打印了这些信息。数据是雄辩模型的一个实例。问题可能只是与数据库交互的底层扩展中的一些细微差异,或者与代码之间的抽象层中的一些实现差异(版本差异?)。信息如此有限,很难说
但是,一般来说,在PHP中,应该假设数据库值作为字符串传递给您,即使它们实际上是数据库中的整数/浮点数/布尔数。假设您需要自己进行类型检查和(如果需要)类型转换
我还要提醒您不要在PHP中进行过度严格的检查。我知道你为什么要这么做,在大多数其他语言中,我都会和你在一起,但PHP的一个定义特征是它对本地类型漠不关心,并且能够在它们之间自动切换,因此,在这种语言中,您不应该试图强制过多的类型严格。您现在应该知道,这还不够。如何查看这些结构和数组?如何填充它们?只是看到一些打印件并不能说明什么是错误的。是的,我知道,但正如前面提到的,我不知道从哪里开始,所以我没有发布太多的信息。我将更新问题,并回答您的评论。感谢您的回复,是mysql服务器本身将其转换为字符串,或者更好地说是PDO扩展。我现在把它修好了。我还将对PHP中的这种严格比较做一些研究。我已经习惯了其他语言中的这一点,并且在PHP中从未看到过这方面的问题(从现在起),谢谢您的提示!