PHP 5.4 WARNING

nickCR

New member
Feb 5, 2010
1,073
12
0
CR
So I needed to upgrade our MySQL server to something a little more modern. We were running 5.1 and we're now at 5.5. In the process I upgraded PHP to 5.4 which is the current stable release of PHP.

Took me about 10 hours to sort out all the problems with our system but the long and short of it is that if you use any variables that push the value back up to the original reference like this &$var1 your program will fail to load.

This method has been REMOVED. It was DEPRECATED in 5.3.

Make sure you check your scripts before upgrading to 5.4!!!!
 


Ughhhhh... Fearing PHP 5.4 myself..

I'm going to be running vBulletin 3.8 on PHP 5.3, and they won't be updating it anymore for PHP 5.4.. Going to drive myself crazy trying to get it to work on my own.. I heard it works perfectly fine on PHP 5.4, but you'll get a ton of errors, and you have to hide them. No critical errors though, just smaller ones.. vB uses Traditional code > Strict code is new for PHP 5.4 is what they said I think... I refused to upgrade to vb 4 or 5, even though I own the license, I hate it, and their idea of how a forum should be..

PM me if you're available for hire. At some point or later, I'm going to need to hire someone to go through the error log, and modify the code here and there to hide all the errors..
 
Well, that fucken sucks... I use that... not all over the place, but I do use it. There's times when it's really convenient.

What is this &$ stuff?

Denotes a reference. For example:

Code:
$x=5;
$y=2;

play_game($x, $y);

function play_game($x, &$y) { 
   $x = 9;
   $y = 4;
}

After the function is called, $x is still 5, while $y is now 4.
 
Well, that fucken sucks... I use that... not all over the place, but I do use it. There's times when it's really convenient.



Denotes a reference. For example:

Code:
$x=5;
$y=2;

play_game($x, $y);

function play_game($x, &$y) { 
   $x = 9;
   $y = 4;
}

After the function is called, $x is still 5, while $y is now 4.


The fuck... I've been coding a long time, circa 1995, thank god not in php, cause I don't see that shit working right here. Maybe you left some code out, or this is a troll - I don't know anymore.
 
The fuck... I've been coding a long time, circa 1995, thank god not in php, cause I don't see that shit working right here. Maybe you left some code out, or this is a troll - I don't know anymore.

That code I posted? It works fine. I just tested it myself:

Code:
$x=5;
$y=2;

echo "X = $x, Y = $y\n";
play_game($x, $y);
echo "X = $x, Y = $y\n";

function play_game($x, &$y) {
   $x = 9;
   $y = 4;
}

Run that, and the output will be:

Code:
X = 5, Y = 2
X = 5, Y = 4

Or what PHP version are you using? Apparently, if it's v5.4+, it's not going to work. My devel server is v5.3.9.
 
That code I posted? It works fine. I just tested it myself:

Code:
$x=5;
$y=2;

echo "X = $x, Y = $y\n";
play_game($x, $y);
echo "X = $x, Y = $y\n";

function play_game($x, &$y) {
   $x = 9;
   $y = 4;
}

Run that, and the output will be:

Code:
X = 5, Y = 2
X = 5, Y = 4

Or what PHP version are you using? Apparently, if it's v5.4+, it's not going to work. My devel server is v5.3.9.

I didn't use PHP, I was attempting to use logic.

j/k I think I figured it out. there was a '&' symbol, that allows the $y character to change the global setting... Now out of curiosity, WTF? Wouldn't it make more sense to use the '&' symbol to make it so that the $X stayed unchanged instead. I mean, most normal programming languages, when you change a variable locally that's global, it'll change the global value, not keep it the same. That's probably why 5.4 did.

Or am I completely incorrect?
 
The fuck... I've been coding a long time, circa 1995, thank god not in php, cause I don't see that shit working right here. Maybe you left some code out, or this is a troll - I don't know anymore.

it's a scope thing. The two variables in that function are scoped to that function so they won't affect the two identically named variables previously defined up above. But because of the &, you're allowing the function to modify the original variable by passing in a reference of that variable to the function rather just the value of that variable.
 
Or am I completely incorrect?

No, you're completely correct. PHP's variable scope is fucken retarded. It will always localize variables to the function though, unless you have that & mark in front.

My current project requires some Perl scripts as well for back-end processes, so after writing in Perl for a few hours, and switching back to PHP, I end up feeling like a dirty hooker.

No variable or type declarations, nothing. Just type in variables wherever the hell you want.
 
you can type variables where ever you want as well in PHP, depending on your config....

this is why I am going back to haskell
 
it's a scope thing. The two variables in that function are scoped to that function so they won't affect the two identically named variables previously defined up above. But because of the &, you're allowing the function to modify the original variable by passing in a reference of that variable to the function rather just the value of that variable.

That's what I deducted. Sorry for my language, PHP is fucking retarded. If a variable has the same identical name, which it shouldn't, but it should change it globally, then if you put a special symbol like in this case '&' it will state not change it globally. If this is PHP, fuck I can't think straight now. PHP broke my brain.
 
I can understand why they do it that way, and it's done for beginners. There's no real global variables in PHP (other than $GLOBALS array). For example, if I put "$z = 6" at the top of that code snippet, the play_game() function wouldn't be able to see to $z.

It makes it easier when it comes to debugging. If you're getting an error on line #381, you know that more than likely the error is within that specific function. Whereas with other languages, it could be due to some variable you declared in some other file that you didn't localize.

Nonetheless, I do like Perl better. I like defining / localizing my variables in each subroutine, versus PHP where you just don't even worry about it.
 
PHP is still one of the leading languages on the market and despite the frequent eruption of threads here on WF about Ruby vs PHP or whatever the fuck else, the fact remains that PHP is commonly used.

I built my entire application myself and it has 10's of thousands of lines of code, so the fact that only 2 or 3 things failed was actually quite surprising. I guess I use lots of strict coding which is what 5.4 likes ( I try to change with the times so I don't hit a wall one day ). Actually the only parts that broke were something another coder did a while back, unfortunately one of those things was the db.connector class which is where I have my query structures for calling the database.

I don't recommend upgrading to 5.4 unless you have a specific usage for it. I did it thinking all would be good. Since it's the current stable release, it made sense but I didn't know that function was removed and thus why I came here letting you all know.

I always thought it was a cool feature but never really felt the need for it.

Regarding the variable discussion. I personally like PHP and the way it handles the variables. This makes it easier to make my variables have names that make sense within each function and not be worried about it making changes at a global scope. This can be a major problem when you have several people working on the same project though.

Also you can create vars in many different ways that are accessible almost anywhere with the most common methods probably being $_SESSION and vars within a class. The class var is what I like best as it makes it easy to work with and update at any point in the process from inside or outside the class.
 
PHP is still one of the leading languages on the market and despite the frequent eruption of threads here on WF about Ruby vs PHP or whatever the fuck else, the fact remains that PHP is commonly used.

I built my entire application myself and it has 10's of thousands of lines of code, so the fact that only 2 or 3 things failed was actually quite surprising. I guess I use lots of strict coding which is what 5.4 likes ( I try to change with the times so I don't hit a wall one day ). Actually the only parts that broke were something another coder did a while back, unfortunately one of those things was the db.connector class which is where I have my query structures for calling the database.

I don't recommend upgrading to 5.4 unless you have a specific usage for it. I did it thinking all would be good. Since it's the current stable release, it made sense but I didn't know that function was removed and thus why I came here letting you all know.

I always thought it was a cool feature but never really felt the need for it.

Regarding the variable discussion. I personally like PHP and the way it handles the variables. This makes it easier to make my variables have names that make sense within each function and not be worried about it making changes at a global scope. This can be a major problem when you have several people working on the same project though.

Also you can create vars in many different ways that are accessible almost anywhere with the most common methods probably being $_SESSION and vars within a class. The class var is what I like best as it makes it easy to work with and update at any point in the process from inside or outside the class.

the last few updates to PHP are trying to make it into a more proper language rather than the hacky scripting language it started off as. For them to do that they're having to deprecate things that break shit.
 
Well, that fucken sucks... I use that... not all over the place, but I do use it. There's times when it's really convenient.



Denotes a reference. For example:

Code:
$x=5;
$y=2;

play_game($x, $y);

function play_game($x, &$y) { 
   $x = 9;
   $y = 4;
}

After the function is called, $x is still 5, while $y is now 4.
Wait, this has been deprecated?

Edit: This hasn't been deprecated. What has been deprecated is something like this:

Code:
$x=5;
$y=2;

play_game($x, &$y);

function play_game($x, $y) { 
   $x = 9;
   $y = 4;
}

Balance has been restored to the universe now that I don't have 40 hours rewriting all my code.