Jump to content

Recommended Posts

I have never seen that. By all logic it should not do that...I am interested to test this out and see what comes of it, too bad this computer isn't a dev one =\

 

As for that example, I think you want echo and not $echo :)

 

Just out of curiosity, what version of php and apache are you using?

Link to comment
https://forums.phpfreaks.com/topic/182101-variable-clash/#findComment-960655
Share on other sites

I've never seen that happen before in my life to be completely honest. Btw, you should have your echo line be echo ... not $echo ... that won't even run... will give a parse error.

 

 

I actually just tested that, and it worked perfectly fine. Is there something special you did that I can do to try to recreate the error?

 

 

edit: beaten :(

Link to comment
https://forums.phpfreaks.com/topic/182101-variable-clash/#findComment-960658
Share on other sites

it works for me to just do:

$var = "$cat is $number years old.";

 

I think you missed the point of the post, he seems to be getting overlap when he used $c and his theory is that the variables are messing up cause $cat has a c in it...which I have never seen happen :)

Link to comment
https://forums.phpfreaks.com/topic/182101-variable-clash/#findComment-960951
Share on other sites

hai

if i am correct u might have used the echo as of below

$c=5;
$cat="Molly";
echo $c."at is ".$c." years old.";
?>

 

this is the only way u can get this error..

 

 

Firstly, that doesn't throw and error.  Second, I'm not sure you guys are understanding the whole point.  As premiso previously  mentioned:

 

I think you missed the point of the post, he seems to be getting overlap when he used $c and his theory is that the variables are messing up cause $cat has a c in it...which I have never seen happen :)

Link to comment
https://forums.phpfreaks.com/topic/182101-variable-clash/#findComment-961063
Share on other sites

Yes, it has happened to me in the past and just happened to me again.

 

No, that wasn't the exact code, I just quickly typed it to give a simple example. Excuse the error, I was in a rush (yeah, that's what they all say).

 

It just happened using this code...

 

function encode_username($username) {
$username = strtolower($username);
$clean = '';
for($i = 0;$i < strlen($username);$i++) {
	$c = ord($username{$i});
	if($c >= 97 && $c <= 122) {
		$clean .= chr($c);
	}
	else if($c >= 48 && $c <= 57) {
		$clean .= chr($c);
	}
	else {
		$clean .= ' ';
	}
}
$clean = trim($clean);
if(strlen($clean) > 12) {
	$clean = substr($clean, 0, 12);
}
$hash = '0';
for($i = 0;$i < strlen($clean);$i++) {
	$c = ord($clean{$i});
	$hash = bcmul($hash, 37);
	if($c >= 97 && $c <= 122) {
		$hash = bcadd($hash, (1 + $c) - 97);
	}
	else if($c >= 48 && $c <= 57) {
		$hash = bcadd($hash, (27 + $c) - 48);
	}
}
return $hash;
}

 

My friend wrote a form script that got their character name as a variable $cname. We couldn't see what the problem was, but after doing a Find & Replace (automatically) from $cname to $bname, it suddenly worked. We could only presume that the $c in the external function (which has been included) was overlapping and causing problems.

 

I had this happen to me ages ago, but I took a long time away from PHP and only recently came back... But yeah, I'm 99.9% sure it does happen under some circumstances!

Link to comment
https://forums.phpfreaks.com/topic/182101-variable-clash/#findComment-962326
Share on other sites

PS. This is on a Windows Server 2003 machine running the latest XAMPP, but this happened to me years ago on shared Linux hosting too. I've always been really paranoid of variables and called them very tricky names just to make sure they don't clash with each other.

Link to comment
https://forums.phpfreaks.com/topic/182101-variable-clash/#findComment-962327
Share on other sites

Well, we had a variable called:

 

$cname = "Kryptix";

 

We'd then remotely call that function...

 

encode_username($cname);

 

...and it'd give us really weird results. We changed it to $bname and it worked fine.

 

I presume the $c in $cname was causing the problems, as I've seen it happen before.

Link to comment
https://forums.phpfreaks.com/topic/182101-variable-clash/#findComment-962401
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.