English 中文(简体)
PHP 5 functioning returning an array- interaction without assignment?
原标题:

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?

最佳回答

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.

问题回答

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





相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签