PHP Redbean ORM - preserve types when json encoding

brux Source

Whenever I var_dump a bean, all the fields are Strings. Is this the expected behaviour? I would like to be able to json_encode() my beans and preserver the type of each field, rather than every value being in quotes (strings).

var_dump($beans)

array(2) {
  [1]=>
  object(RedBeanPHP\OODBBean)#418 (10) {
    ["properties":protected]=>
    array(3) {
      ["id"]=>
      string(1) "1"
      ["name"]=>
      string(14) "United Kingdom"
      ["code"]=>
      string(2) "GB"
    }
    ["__info":protected]=>
    array(5) {
      ["type"]=>
      string(7) "country"
      ["sys.id"]=>
      string(2) "id"
      ["sys.orig"]=>
      array(3) {
        ["id"]=>
        string(1) "1"
        ["name"]=>
        string(14) "United Kingdom"
        ["code"]=>
        string(2) "GB"
      }
      ["tainted"]=>
      bool(false)
      ["changed"]=>
      bool(false)
    }
    ["beanHelper":protected]=>
    object(RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper)#12 (0) {
    }
    ["fetchType":protected]=>
    NULL
    ["withSql":protected]=>
    string(0) ""
    ["withParams":protected]=>
    array(0) {
    }
    ["aliasName":protected]=>
    NULL
    ["via":protected]=>
    NULL
    ["noLoad":protected]=>
    bool(false)
    ["all":protected]=>
    bool(false)
  }
  [2]=>
  object(RedBeanPHP\OODBBean)#406 (10) {
    ["properties":protected]=>
    array(3) {
      ["id"]=>
      string(1) "2"
      ["name"]=>
      string(9) "Singapore"
      ["code"]=>
      string(2) "SG"
    }
    ["__info":protected]=>
    array(5) {
      ["type"]=>
      string(7) "country"
      ["sys.id"]=>
      string(2) "id"
      ["sys.orig"]=>
      array(3) {
        ["id"]=>
        string(1) "2"
        ["name"]=>
        string(9) "Singapore"
        ["code"]=>
        string(2) "SG"
      }
      ["tainted"]=>
      bool(false)
      ["changed"]=>
      bool(false)
    }
    ["beanHelper":protected]=>
    object(RedBeanPHP\BeanHelper\SimpleFacadeBeanHelper)#12 (0) {
    }
    ["fetchType":protected]=>
    NULL
    ["withSql":protected]=>
    string(0) ""
    ["withParams":protected]=>
    array(0) {
    }
    ["aliasName":protected]=>
    NULL
    ["via":protected]=>
    NULL
    ["noLoad":protected]=>
    bool(false)
    ["all":protected]=>
    bool(false)
  }
}
phpormredbean

Answers

comments powered by Disqus