1

I'm learning object oriented php. I've come across some code I don't fully understand. This code is within a class.

1) code that uses @. For example:

$this->image = @imagecreatefromgif($filename);

Can some one explain the uses of @.

2) Also it looks like the script is declaring variables in a way i'm not used to (the $var way).

For example:

$this->ext = $size['mime'];

$ext is not declared before this code is used, but it used after it. Does this create an $ext variable within the object?

Thanks guys!!

tereško
  • 58,060
  • 25
  • 98
  • 150
seamus
  • 2,681
  • 7
  • 26
  • 49
  • 7
    When to use [`@`](http://php.net/manual/en/language.operators.errorcontrol.php)? Never. Anything relying on `@` to silently ignore any errors and warnings is very likely badly designed. – rid Aug 01 '13 at 17:04
  • 1
    Try not to ask unrelated questions in the same post, it confuses things. For the second question, see http://stackoverflow.com/questions/10042736/class-works-without-declaring-variables?rq=1 – Barmar Aug 01 '13 at 17:06
  • Barmar to the rescue again. Thanks! – seamus Aug 01 '13 at 17:10
  • Wow, Thanks. Reference - What does this symbol mean in PHP? is gonna be a life saver. – seamus Aug 01 '13 at 17:16
  • Yours welcome ...There are plenty of more like this http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php but you need to do some re search to find them :) – NullPoiиteя Aug 01 '13 at 17:32

3 Answers3

1

The @ will suppress errors so that no errors will be shown for that expression.

http://php.net/manual/en/language.operators.errorcontrol.php

Jake N
  • 10,535
  • 11
  • 66
  • 112
1

@ is php's error suppression operator you should never use it

You should handle error instead ignoring and advantage would be you will get long notice which is helpful to debug too

And worst case would be below as described in manual

Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.

NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
0

@ Means "Suppress warning when calling this function".

MightyPork
  • 18,270
  • 10
  • 79
  • 133