php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59480 Accessing a SolrObject array item directly
Submitted: 2010-10-27 10:08 UTC Modified: 2013-02-18 00:35 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: dvdm80 at gmail dot com Assigned:
Status: No Feedback Package: solr (PECL)
PHP Version: 5.3.2 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dvdm80 at gmail dot com
New email:
PHP Version: OS:

 

 [2010-10-27 10:08 UTC] dvdm80 at gmail dot com
Description:
------------
I'm trying to get an item of an array by its key. The array 
is in fact a 
SolrObject, which implements ArrayAccess, so I understand 
that I can access its 
items as I would in an array. This object is retrieved by 
the getResponse() 
method of the SolrQueryResponse class 
(php.net/manual/en/solrresponse.getresponse.php).

This is the structure of my $myobject:

SolrObject Object
(
    [116809] => SolrObject Object
    (
        [title] => Array
        (
            [0] => First value
        )

        [description] => Array
        (
            [0] => Second value
        )

    )

    [591978] => SolrObject Object
    (
        [title] => Array
        (
            [0] => Third value
        )

        [description] => Array
        (
            [0] => Forth value
        )
    )
)
So, if I try

var_dump($myobject[116809]);
I get NULL.

But if I try

echo array_key_exists(116809, $myobject);
I get 1

If I try to iterate $myobject with a foreach, I can access 
its elements 
correctly.

Why can't I access directly one element by its key?

EDIT: Answering to @ircmaxell, this is the var_dump:

object(SolrObject)#219 (50) {
  [116809]=>
  object(SolrObject)#220 (2) {
    ["title"]=>
    array(1) {
      [0]=>
      string(43) "First value"
    }
    ["description"]=>
    array(1) {
      [0]=>
      string(82) "Second value"
    }
  }
  [591978]=>
  object(SolrObject)#221 (2) {
    ["title"]=>
    array(1) {
      [0]=>
      string(104) "Third value"
    }
    ["description"]=>
    array(1) {
      [0]=>
      string(95) "Fourth value"
    }
  }
}
And this is the result of var_dump($myobject-
>getPropertyNames());

array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-01 10:47 UTC] insekticid at gmail dot com
I have similar problem, it is impossible to access item with 
nummeric key

$collapseValue = 131313;
//do not work
$collapseRows = $result->$collapseValue;
$collapseRows = $result->{$collapseValue};
$collapseRows = $result->offsetGet($collapseValue);
$collapseRows = $result[$collapseValue];

//works!
$collapseRows = (array)$result;
$collapseRows = $collapseRows[$collapseValue];
 [2011-06-04 04:14 UTC] iekpo@php.net
In the next release you can avoid this problem by using the json response writer.

You just need to set wt == json in the SolrClient constructor
 [2013-02-18 00:35 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 14:01:30 2024 UTC