b/w可数对象与不可数对象有什么区别 [英] What is the difference b/w Countable and Non Countable Objects

查看:66
本文介绍了b/w可数对象与不可数对象有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出差异b/w是可数对象和不可数对象

I am trying out to find difference b/w a countable and a non countable object

首先,我找到了对象的类型

First I found out the Type of object

echo gettype($data["current_fiat_currency"]);

哪个是 Object

但是当我检查它是否为可数对象时

But when i had checked that it is a countable object or not

var_dump($data["current_fiat_currency"] instanceof Countable );

然后返回

 False

下面是对象内容

var_dump($data["current_fiat_currency"]);

object(stdClass)[2010]
  public 'id' => string '1399' (length=4)
  public 'currency_name' => string 'US Dollar' (length=9)
  public 'currency_slug' => string '' (length=0)
  public 'currency_code' => string 'USD' (length=3)
  public 'currency_logo' => string '0' (length=1)
  public 'currency_type' => string '3' (length=1)
  public 'logo' => string '.png' (length=4)
  public 'exe' => string '0' (length=1)
  public 'logo_exe' => string '1' (length=1)
  public 'symbol_native' => string '$' (length=1)
  public 'symbol' => string '$' (length=1)
  public 'name_plural' => string 'US dollars' (length=10)
  public 'market_cap' => string '0' (length=1)
  public 'circulating_supply' => string '0' (length=1)
  public 'max_supply' => string '0' (length=1)
  public 'total_supply' => string '0' (length=1)
  public 'cryptoid_info_exe' => string '0' (length=1)
  public 'show_on_website' => string '1' (length=1)
  public 'default_selected' => string '1' (length=1)
  public 'exchange_rate' => string '1' (length=1)
  public 'currencies_stats_exe' => string '0' (length=1)
  public 'currencies_stats_last_updated' => null
  public 'mineable_or_not' => string '0' (length=1)
  public 'show_on_top_bar' => string '0' (length=1)
  public 'added_date' => string '2018-01-11 05:21:37' (length=19)
  public 'graph_size_chart_status' => string '0' (length=1)
  public 'twitter' => null
  public 'reddit' => null
  public 'status' => string '1' (length=1)
  public 'for_pair_status' => string '0' (length=1)

因此,如果我根据Php 7.0正常工作,那么如何根据php 7.2将现有对象转换为可数,该如何将其转换为可数.

So how i can convert a existing object to countable if it is not countable according to Php 7.2 because my codes working fine with Php 7.0.

推荐答案

可能是黑客

echo count((array) $data["current_fiat_currency"]);

这只是一个补丁解决方案,我认为它仅在某些情况下有效,您不应依赖它.

It's just a patching solution and I think it'll work in just some cases and you should not rely on it.

这篇关于b/w可数对象与不可数对象有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆