Page 2 of 2
Posted: Thu Dec 30, 2004 5:30 pm
by shiznatix
wow suprisingly (to me) that worked! tell me what the & sign did so i can actually learn. thank you so much thou!
Posted: Thu Dec 30, 2004 5:36 pm
by feyd
the & sign just asked php to make $newstring2 a reference to $array[$i], instead of a copy (saves some memory, and processing time)
While a reference, if you alter $newstring2 or $array[$i], it'll change the other (basically).. If you know C, it's a pointer.
Posted: Thu Dec 30, 2004 5:39 pm
by shiznatix
thanks a bunch
Posted: Thu Dec 30, 2004 6:07 pm
by shiznatix
off topic and probebly a stupid question but every time i create then write to a text file the first line is a blank line then the text starts on the second line. iv used the "r" mode to open it and the "r+" mode to write to it and it still goes to the second line no matter what. why is this and how do i get around it happening?
Posted: Thu Dec 30, 2004 6:59 pm
by feyd
you probably have a carriage return as one of the first characters in the file.. if you use a function like [php_man]trim()[/php_man] on each line then add a carriage return to it (making sure not to write blank lines.. it should help...
ghetto way: just remove the line manually..

Posted: Thu Dec 30, 2004 8:07 pm
by Chris Corbyn
I didn't know that thing about the ampersand. Useful tip

Posted: Fri Dec 31, 2004 9:05 am
by Robert Plank
I love being able to use references for cool stuff but it looks like PHP is phasing them out.

I'm not saying don't learn them but if you have a script you plan on going out to a lot of people, that uses references, it might break. I had to rewrite a lot of code because of this not too long ago.
New versions of PHP have a setting on whether or not to complain about about references, I'm not sure if it's turned on by default or not, but basically it says not to use them in the future. Just so you know...
Posted: Fri Dec 31, 2004 11:06 am
by rehfeld
Robert Plank wrote:I love being able to use references for cool stuff but it looks like PHP is phasing them out.

I'm not saying don't learn them but if you have a script you plan on going out to a lot of people, that uses references, it might break. I had to rewrite a lot of code because of this not too long ago.
New versions of PHP have a setting on whether or not to complain about about references, I'm not sure if it's turned on by default or not, but basically it says not to use them in the future. Just so you know...
references are definately not being phased out.
in php5 objects are automatically passed by reference.
maybe your talking about :
allow_call_time_pass_reference
if set to on, this lets you specify whether a variable should be passed by reference when calling the function itself.
Code: Select all
// good, not being phased out way that will always work
function add_foo(&$text) { // notice reference is func definition
$text .= 'foo';
}
$bar = 'bar';
add_foo($bar); // $bar is now == 'barfoo'
//
//
//
// bad way, in php5, only works if: allow_call_time_pass_reference = On
function add_foo($text) { // notice NO reference is func definition
$text .= 'foo';
}
$bar = 'bar';
add_foo(&$bar); // notice reference at call_time, bad
so its not that references are bad, its just the way you use them. what feyd did is not affected by this at all, and totally allowed.
Posted: Fri Dec 31, 2004 12:32 pm
by Robert Plank
Hey rehfeld, yeah I was talking about allow_call_time_pass_reference in PHP4. Man that just made my day. Other people were having that problem on their servers and not mine, and I thought I was forced to not use references. Now I know that I can... SWEET!!