LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Help, What's the meaning of this Parse error?? (https://www.linuxquestions.org/questions/programming-9/help-whats-the-meaning-of-this-parse-error-488040/)

jason1074 09-29-2006 12:16 PM

Help, What's the meaning of this Parse error??
 
Can somebody please help me? What's the meaning of this Parse error?

The Parse error reads:
syntax error, unexpected T_IF in /home/shoutout/public_html/thumb/class.php on line 1043

Below are lines 1042,1043 and 1044.


{
$GIFtemp = if ($this->getimagesizeinfo[2] == 1);
$ImageCreateFunction = ($GIFtemp ? 'ImageCreateFromGIF' : 'ImageCreateFromPNG');



Thank you,
Jay

i_grok 09-29-2006 12:47 PM

You can't have an if() statement with a semicolon after it. You should have something like this:
Code:

if($this->getimagesizeinfo[2] == 1) {
  $ImageCreateFunction = ($GIFtemp ? 'ImageCreateFromGIF' : 'ImageCreateFromPNG');
}


nadroj 09-29-2006 12:57 PM

Quote:

You can't have an if() statement with a semicolon after it.
i dont know PHP, but this must be PHP-specific, no?

MOS JEFF-INITELY 09-29-2006 01:10 PM

yes, Perl/PHP (PHP is a subset of Perl)

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

95se 09-29-2006 01:13 PM

It's valid php. For instance, this works:

Code:

if(true);
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
Code:

$GIFtemp = $this->getimagesizeinfo[2] == 1

95se 09-29-2006 01:18 PM

Quote:

Originally Posted by MOS JEFF-INITELY
yes, Perl/PHP (PHP is a subset of Perl)

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.

paulsm4 09-29-2006 01:20 PM

Hi -

I_grok is right:
Code:

  // 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:

http://www.devarticles.com/c/a/PHP/M...-PHP-Errors/1/

'Hope that helps .. PSM

MOS JEFF-INITELY 09-29-2006 01:42 PM

Quote:

Originally Posted by 95se
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.

not true, I'm a Perl person myself havent used PHP much, but I do know that PHP syntax is based on Perl and a bit of C.

The major differences PHP is made directly for web page scripting where as Perl script is used more generically and not only for web pages.

Although there are obvious differences, Perl has web extensions in CPAN that make PHP and Perl scripts very similar.

jason1074 09-29-2006 02:40 PM

Thank you everyone for trying to help me. I tried to fix the code myself but I kept getting other parse errors. I'm a total dummy with these codes.

The error was on line 1043 after fixing the code according to everyones input I started getting an error on line 1700.

Would anyone like to check it out and let me know what I need to do? I really appreciate all the help.

Jay

jason1074 09-29-2006 02:43 PM

Here's the next erro:

Parse error: syntax error, unexpected ':' in /home/shoutout/public_html/thumb/class.php on line 1700

Line 1700:
$dither = (0 < strlen ($dither) ? : true);

paulsm4 09-29-2006 03:01 PM

Please look back at my previous link - it's the same problem:
http://www.linuxquestions.org/questi...80#post2443080

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.

'Hope that helps .. PSM

bulliver 09-30-2006 10:49 AM

Quote:

PHP is a subset of Perl
Eh??

I don't think so man. Except for trivial syntax similarities they are completely unrelated.


All times are GMT -5. The time now is 11:53 PM.