0

I have the following stdClass:

object(stdClass)#1 (2) {
  ["3afa3501461570b33a8f8efeae4faa39"]=>
  object(stdClass)#2 (3) {
    ["filename"]=>
    string(36) "3afa3501461570b33a8f8efeae4faa39.jpg"
    ["alt"]=>
    string(23) "Kismama Párna Virágos"
    ["caption"]=>
    string(1008) " Ez az egyedülálló, ergonómikus kialakítású párna, a babákat a megfelelő magasságba, és pozícióba helyezésével segíti, és kényelmesebbé teszi a kisbabák etetését 

  • Tartós, minőségi anyag
 • Könnyen újratölthető
 • Egyszerűen tisztítható
 •  Antiallergén, gyerekbarát

 Anyaga: mosható, 100 % pamutvászon (belső), 100% mosható pamut(külső) 

  Mérete:120x40 cm  

 Az ár bruttó ár, mely tartalmazza a 27% Áfá-t 

  Szállítási idő: 1-3 hét

"
  }

I would like access only the [filename] value but $var->filename; not working, i get the following error: PHP Notice: Undefined property: stdClass::$filename in.

The stdClass name ["3afa3501461570b33a8f8efeae4faa39"] is randomly every mysql rows.

thank you for your help!

2
  • 3
    $var->3afa3501461570b33a8f8efeae4faa39->filename Commented Oct 3, 2014 at 20:37
  • this cause he following error: PHP Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or ' (the "3afa3501461570b33a8f8efeae4faa39" is an random number, beacuse CI is coded when save to database) Commented Oct 3, 2014 at 20:43

1 Answer 1

1

Use this:

<?php
foreach($object as $file){}
echo $file->filename;
?>

or

<?php    
echo $object->{end(array_keys((array)$object))}->filename;
?>

Demo: https://eval.in/201681

Sign up to request clarification or add additional context in comments.

1 Comment

PHP Notice: Trying to get property of non-object in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.