ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
However, you cannot assign an if statment to a variable. Why do you have that random if there? If your trying to assign the result of an equality, just do
in other languages you can run one statement without using {} however in Perl/PHP this is not allowed you need the {} or you will get an error
No, the {} is not needed. PHP is meant to be easy to use... it's very hard to write code that doesn't work in php. I wouldn't compare php and perl either, they're very different. I think people just think of perl when they see php because of the dollar signs.
// Permissible (but weird) in C/C++, but it's a parse error in PHP
$GIFtemp = if ($this->getimagesizeinfo[2] == 1); // Set $GIFtemp to TRUE or FALSE
$ImageCreateFunction =
($GIFtemp ? 'ImageCreateFromGIF' : 'ImageCreateFromPNG');
Code:
// Correct in PHP ... clearer in any language
if ($this->getimagesizeinfo[2] == 1) {
$ImageCreateFunction = 'ImageCreateFromGIF';
}
else {
$ImageCreateFunction = 'ImageCreateFromPNG';
}
This link might help explain these kinds of PHP error messages a bit better:
1. As far as the real problem:
You do NOT want to create boolean expressions like "$dither = (0 < strlen ($dither) ? : true);" if you can do the same thing with a conditional like "if (strlen ($dither) > 0) {...}"
2. As far as whether or not you need "{}":
No, you don't.
The problem isn't braces, the problem is trying to use a boolean expression instead of just using a simple "if/then/else".
3. As far as the relationship between Perl and PHP:
The answer is ultimately a matter of taste. Sure, they're both "C-like". And sure, they're both scripting languages.
But they were written by different people, for different purposes, run in different environments, and have different strengths and weaknesses.
Personally, I think the two are more dissimilar than not.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.