0

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?

2 Answers 2

3

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.

0

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

0

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.