-1

I am working with RedBeansPHP 3.3 and have the following PHP object created by RedBeans findOne called $result:

RedBean_OODBBean Object
(
    [null:RedBean_OODBBean:private] => 
    [properties:RedBean_OODBBean:private] => Array
        (
            [id] => 10
            [datetime] => 2013-02-10 10:17:43
            [ip] => 68.32.52.219
            [vcode] => 6780-QBDY
            [roll1] => 7
            [roll2] => 8
            [roll3] => 10
            [roll4] => 6
            [roll5] => 1
            [roll6] => 4
            [roll7] => 2
            [roll8] => 4
            [roll9] => 2
            [roll10] => 8
        )

    [__info:RedBean_OODBBean:private] => Array
        (
            [type] => dice
            [sys.id] => id
            [tainted] => 
            [sys.orig] => Array
                (
                    [id] => 10
                    [datetime] => 2013-02-10 10:17:43
                    [ip] => 68.32.52.219
                    [vcode] => 6780-QBDY
                    [roll1] => 7
                    [roll2] => 8
                    [roll3] => 10
                    [roll4] => 6
                    [roll5] => 1
                    [roll6] => 4
                    [roll7] => 2
                    [roll8] => 4
                    [roll9] => 2
                    [roll10] => 8
                )

        )

    [beanHelper:RedBean_OODBBean:private] => RedBean_BeanHelper_Facade Object
        (
        )

    [fetchType:RedBean_OODBBean:private] => 
    [withSql:RedBean_OODBBean:private] => 
    [aliasName:RedBean_OODBBean:private] => 
)

I want to access the value [type] => dice in the second array. What is the PHP syntax for that?

$result->???????->type [Am I close?]

Thanks!

Phillip Berger
  • 2,317
  • 1
  • 11
  • 30
  • The `__info` array property is a `private` property, meaning you cannot access it unless you modify the class to write a getter method for it. I isn't accessible from an object variable like your `$result` appears to be. – Michael Berkowski Feb 10 '13 at 15:38
  • Not sure if [the API](http://redbeanphp.com/api/da/d65/class_red_bean___o_o_d_b_bean.html) already provides a way to access it. – Michael Berkowski Feb 10 '13 at 15:40
  • I can access the entire first array by saying `$result->ip` or whatever in place of ip. That is also labeled `private`. Stands to reason I should be able to access the second array? – Phillip Berger Feb 10 '13 at 15:45
  • Not so - if you're doing `$result->ip` what you are getting back is not directly the value from the `properties` array. That is `private`, and you _cannot_ directly access private properties outside of class methods. Please post the PHP code you're using to get the ip, as it cannot be via `$result->properties['ip']` (could be via `$this->properties['ip']` if you are working inside a class method) – Michael Berkowski Feb 10 '13 at 15:49
  • If I do: `$var = $result->ip; echo $var;` I do get `68.32.52.219` returned. – Phillip Berger Feb 10 '13 at 15:55
  • Ok, but that _isn't_ the same property as the `ip` you listed above. The `ip` above is inside the `properties` array, which is private. `$result->ip` is a direct property of the object `$result`. You need to post your code. What is it you are even dumping above? Is that `var_dump($result)`? – Michael Berkowski Feb 10 '13 at 16:06
  • Posted the code in the body of my original question as an edit. – Phillip Berger Feb 10 '13 at 16:51

1 Answers1

0

Wanted anyone to know who was searching for an answer that I got it from the RedBeans creator.

You can access a RedBeans type by saying:

$beanTable = $bean->getMeta('type');
Phillip Berger
  • 2,317
  • 1
  • 11
  • 30