Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm wondering if this kind of thing will ever be possible in PHP (and whether it already is and I'm just missing something...)

<?php

function test() {
 return array(
  'id'=>10,
  'name'=>'John'
 );
}

echo 'Your name is: '.test()['name'];

?>

I'd really like to be able to use returned arrays directly instead of first assigning them to a var... possible?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Simple answer: don't think so

The PHP lexer doesn't recognize these kind of statements so a change would require some major changes within the core components of PHP. Although I must admit, that I don't see any reason why the lexer has been written that way.

share|improve this answer

No you can't do in this way, but with php5 and OOP you have some alternatives...

share|improve this answer
    
Such as?....... –  Lee Mar 12 '10 at 22:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.