Make form_error($permission) get treated like form_error('permission')

dsrnu
dsrnu used Ask the Experts™
on
Make form_error($permission) get treated like form_error('permission')?

I know there's a way to do this.. can't seem to figure it out though.
form_error($permission)

// make it get treated like

form_error('permission')

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelancer
Top Expert 2010
Commented:
I confess to not understand clearly what you exactly mean. Maybe this?

$permission = 'permission';
form_error($permission);
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
Commented:
That is not clear.  Is 'form_error' a function that you are trying to pass data to?  Either of the statements you posted would work but they are not necessarily the same since $permission is a variable and 'permission' is a string constant.

Author

Commented:
dave--i guess im trying to make the variable as a string constant... is there a way to do that?
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Author

Commented:
<?php echo form_error('${permission}'); ?>

and

<?php echo form_error('{$permission}'); ?>

works

http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
Commented:
You're not telling us what you're trying to do so we really can't suggest anything to you.  'form_error' is not a PHP function so it must be something you wrote.  No, you can't "make the variable as a string constant" but if you're passing data to a function, it doesn't matter, the function will just see it as data.
Bernie BsenChef de cuisine
Commented:
Hope to make it clear using an example....

<?php
function form_error($permission) {
    echo "Form error is $permission<br />";
   return true;
}

form_error('permission'); //parameter is string

form_error($permission); // parameter is undefine variable

$permission = "permission 1";
form_error($permission); // parameter is defined variable
exit;
?>

Output of above script is
Form error is permission
Form error is
Form error is permission 1
Most Valuable Expert 2011
Top Expert 2016
Commented:
I think brb6708 shows a pretty good example of what to do here.

Here is a great place to get a foundation in how PHP works: http://www.sitepoint.com/books/phpmysql4/
And here is another: http://www.php.net/tut.php

Information on defining constants in PHP: http://www.php.net/manual/en/function.define.php
Information on using constants in PHP: http://www.php.net/manual/en/language.constants.php
Information on the "scope" of variables and constants is here: http://www.php.net/manual/en/language.variables.scope.php

Best of luck with your project, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial