php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27150 2 feature requests, directly accessing returned arrays, and statics by reference
Submitted: 2004-02-04 13:43 UTC Modified: 2006-04-03 12:36 UTC
From: sven at leon dot uia dot mx Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.0b3 (beta3) OS: All (redhat 90)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 + 12 = ?
Subscribe to this entry?

 
 [2004-02-04 13:43 UTC] sven at leon dot uia dot mx
Description:
------------
I have a number of feature requests:

1) Could it be possible to immediately access an array that was returned from a function, just like its possible to access object functions immediately? This way its easy to safely access arrays that are privately stored inside an object (so that another person can not (accidentally) change information inside that array.

i.e. $temp=$object->return_object($parameter)->data($key);
for an array (that is privately kept inside an object):
     $temp=$object->return_array($parameter)[$key];

where $object->return_array would be like:

function return_array(){
    return $copied_array=$private_array;
}

This same (feature request) has been asked in report 25898, but the given "possible solution" did not seem to match my question. 

2) Could it be possible for functions that accept parameters by reference, and return values by reference, to also accept static value's like strings or booleans?

This would be very nice in situations where I would have to accept a large string PLUS a small piece of text like "hey", and it would be very usefull too in situations where I would  have to return either an array or FALSE.

like this:

$data="hey";
test(TRUE, $data."<br>");
function test($param1, &$param2){
  $data=array($param2, "bye");
  If($param1)
  {
    return $data;
  }
  else
  {
    return FALSE;
  }
}

The above script will fail with beta 3 on both the parameters (since a static string was part of $param2) and the return value (Becouse FALSE is also not a variable)

This is a functionality I have used alot in other programming languages, without problems. Sending strings by reference will (in my opinion) make it possible to optimize your scripts a little more.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-04 13:45 UTC] sven at leon dot uia dot mx
oops: forgot to write correct summarym, done
 [2006-04-03 12:36 UTC] tony2001@php.net
For the first part:
see bug #23920.
As for the second:
the answer is no.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 00:01:29 2024 UTC