PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 5th, 2012, 02:20 PM
dhinged dhinged is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 dhinged User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 56 sec
Reputation Power: 0
PHP 5.4 removing call-time reference for non-object vars?

I can understand deprecating the ampersand (&) for call-time references for objects (like function foo(&$object)) but not for strings etc. This seems useful so I don't have to do this:

$string = foo($string);

It seems like foo(&$string) should be perfectly acceptable and not cause problems or be unnecessary.

Am I missing something here?

Reply With Quote
  #2  
Old December 5th, 2012, 03:07 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,851 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 12 h 36 m 16 sec
Reputation Power: 813
Hi,

this is a misunderstanding. Passing by reference works like it always did, but you have to declare the reference in the function definition, not the function call:
PHP Code:
<?php

function f(&$x) {
    
$x[0] = 'x';
}

$str 'abc';
f($str);        // no, not f(&$str)        
echo $str;

Last edited by Jacques1 : December 5th, 2012 at 03:12 PM.

Reply With Quote
  #3  
Old December 10th, 2012, 06:03 PM
rstoll rstoll is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 rstoll User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 3 m
Reputation Power: 0
Well, you could say in a readability point of view output parameters are quite misleading, and $string = foo($string); is the better approach. But that's just my opinion (and the opinion of some design guru's)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP 5.4 removing call-time reference for non-object vars?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap