Jump to content

[SOLVED] Passing a variable through a function?


N1CK3RS0N

Recommended Posts

Hello,

 

I was wondering if its possible to pass a variable through a function?

 

Something like this:

 

<?php

function cows($noise) {
if ($noise == moo) {
	$say = "Hi Mr. Cow";
} else {
	$say = "Your no Cow fool!";
}
}

cows('moo');

echo $say;

?>

 

The 'Echo $say;' does nothing.

you need to pass by reference. a variable created inside a function is localized to that function.

 

http://php.net/language.references.pass

 

 

Hmm. That confuses me. Is there no other way? Don't think that will work for what I'm trying to do.

or declare a global variable. what are you trying to do?

 

I have a number of things going to be using a function. Its checking file permissions. If every file permission meets requirements then the submit button on the form works, otherwise it is disabled.

 

<?php

$pass = "true";

function check_perms($file, $perm) {
if (substr(decoct(fileperms("$file")),2) == $perm) {
	return "<div class=\"container\" style=\"color: #008000; font-weight:bold;\">Pass</div>";
} else {
	$pass = "false";
	return "<div class=\"container\" style=\"color: #D00000; font-weight:bold;\">Fail</div>";
}
}

$backups = check_perms('../backups/', '777');
$downloads_uploads = check_perms('../downloads/uploads/', '777');
$images_uploads = check_perms('../images/uploads/', '777');
$images_banners = check_perms('../images/banners/', '777');
$include_config = check_perms('../includes/config.php', '666');
$languages = check_perms('../languages/', '777');
$modules = check_perms('../modules/', '777');
$templates = check_perms('../templates/', '777');

if ($pass == 'true') {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}"\ name=\"submit\" />";
} else {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}"\ name=\"submit\" disabled=\"disabled\" />";
}

?>

 <?php

$pass = "true";

function check_perms($file, $perm,&$pass) {
if (substr(decoct(fileperms("$file")),2) == $perm) {
	return "<div class=\"container\" style=\"color: #008000; font-weight:bold;\">Pass</div>";
} else {
	$pass = "false";
	return "<div class=\"container\" style=\"color: #D00000; font-weight:bold;\">Fail</div>";
}
}

$backups = check_perms('../backups/', '777',$pass);
$downloads_uploads = check_perms('../downloads/uploads/', '777'$pass);
$images_uploads = check_perms('../images/uploads/', '777',$pass);
$images_banners = check_perms('../images/banners/', '777',$pass);
$include_config = check_perms('../includes/config.php', '666',$pass);
$languages = check_perms('../languages/', '777',$pass);
$modules = check_perms('../modules/', '777',$pass);
$templates = check_perms('../templates/', '777',$pass);

if ($pass == 'true') {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}" name="submit\" />";
} else {
$input_button = "<input type=\"submit\" id=\"submit\" value=\"{$LANG.submit_button}" name="submit\" disabled=\"disabled\" />";
}

?>

 

try that

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.