Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6126 > unrolled thread
| Started by | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| First post | 2012-05-23 08:47 -0430 |
| Last post | 2012-05-24 22:26 +0200 |
| Articles | 12 — 4 participants |
Back to article view | Back to comp.lang.php
On the usage of "@" (error control operator) "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-23 08:47 -0430
Re: On the usage of "@" (error control operator) Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-23 09:50 -0400
Re: On the usage of "@" (error control operator) "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-23 10:19 -0430
Re: On the usage of "@" (error control operator) Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-23 12:12 -0400
Re: On the usage of "@" (error control operator) "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-23 14:15 -0430
Re: On the usage of "@" (error control operator) Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-23 16:14 -0400
Re: On the usage of "@" (error control operator) Shake <QUITAESTO@QUITAESTO.NOES> - 2012-05-23 16:12 +0200
Re: On the usage of "@" (error control operator) "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-23 10:22 -0430
Re: On the usage of "@" (error control operator) Shake <QUITAESTO@QUITAESTO.NOES> - 2012-05-23 17:11 +0200
Re: On the usage of "@" (error control operator) "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-23 10:44 -0430
Re: On the usage of "@" (error control operator) Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-23 12:13 -0400
Re: On the usage of "@" (error control operator) Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2012-05-24 22:26 +0200
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Date | 2012-05-23 08:47 -0430 |
| Subject | On the usage of "@" (error control operator) |
| Message-ID | <jpio02$942$1@dont-email.me> |
Hi, A few weeks ago, I wrote this sentence: @$retVal = $this->lastfetch[$ndx]; Yesterday, browsing the manual, I found this paragraph: "PHP supports one error control operator: the at sign (@). _When prepended to an expression_ in PHP, any error messages that might be generated by that expression will be ignored." and, a few lines further: "A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it." Since an assigment is not an expression, the required syntax should be: $retVal = @$this->lastfetch[$ndx]; But both forms work. Is there any reason to prefer one above the other? --
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-05-23 09:50 -0400 |
| Message-ID | <jpiq01$km7$1@dont-email.me> |
| In reply to | #6126 |
On 5/23/2012 9:17 AM, Leonardo Azpurua wrote: > Hi, > > A few weeks ago, I wrote this sentence: > > @$retVal = $this->lastfetch[$ndx]; > > Yesterday, browsing the manual, I found this paragraph: > > "PHP supports one error control operator: the at sign (@). _When prepended > to an expression_ in PHP, any error messages that might be generated by that > expression will be ignored." > > and, a few lines further: > > "A simple rule of thumb is: if you can take the value of something, you can > prepend the @ operator to it." > > Since an assigment is not an expression, the required syntax should be: > > $retVal = @$this->lastfetch[$ndx]; > > But both forms work. > > > Is there any reason to prefer one above the other? > > -- > > My preference is to not use it at all and fix the error. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Date | 2012-05-23 10:19 -0430 |
| Message-ID | <jpitd2$bc8$1@dont-email.me> |
| In reply to | #6127 |
"Jerry Stuckle" <jstucklex@attglobal.net> escribió en el mensaje news:jpiq01$km7$1@dont-email.me... >> [snip] >> Since an assigment is not an expression, the required syntax should be: >> >> $retVal = @$this->lastfetch[$ndx]; >> >> But both forms work. >> >> >> Is there any reason to prefer one above the other? >> >> -- >> >> > > My preference is to not use it at all and fix the error. > Hi, In this case there is no error to fix. I am writing (mostly for study purposes) a Web Interface to the reports of a business system of mine. This reports are generated from a user-generated script contained in a text file. Data items may come from several sources, like script defined variables, predefined variables, input parameters, database columns or script defined formulas. So, I must search an identifier in several associative arrays. And trying to access an array element with an invalid index triggers an error. An alternative would be to walk the array comparing each key with the desired identifier, but it means more code and, probably, less efficiency (even with the overhead of the @ operator). Anyway, any advice regarding a cleaner way to do this, will be very appreciated. Thanks!
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-05-23 12:12 -0400 |
| Message-ID | <jpj296$bh7$1@dont-email.me> |
| In reply to | #6129 |
On 5/23/2012 10:49 AM, Leonardo Azpurua wrote: > "Jerry Stuckle"<jstucklex@attglobal.net> escribió en el mensaje > news:jpiq01$km7$1@dont-email.me... >>> [snip] >>> Since an assigment is not an expression, the required syntax should be: >>> >>> $retVal = @$this->lastfetch[$ndx]; >>> >>> But both forms work. >>> >>> >>> Is there any reason to prefer one above the other? >>> >>> -- >>> >>> >> >> My preference is to not use it at all and fix the error. >> > > Hi, > > In this case there is no error to fix. > > I am writing (mostly for study purposes) a Web Interface to the reports of a > business system of mine. This reports are generated from a user-generated > script contained in a text file. > > Data items may come from several sources, like script defined variables, > predefined variables, input parameters, database columns or script defined > formulas. > > So, I must search an identifier in several associative arrays. And trying to > access an array element with an invalid index triggers an error. > Then there is an error. So, the solution is to check to see if the element exists before trying to access it. > An alternative would be to walk the array comparing each key with the > desired identifier, but it means more code and, probably, less efficiency > (even with the overhead of the @ operator). > Maybe, maybe not. It depends on a lot of factors. > Anyway, any advice regarding a cleaner way to do this, will be very > appreciated. > > Thanks! > > -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Date | 2012-05-23 14:15 -0430 |
| Message-ID | <jpjb7d$8ru$1@dont-email.me> |
| In reply to | #6135 |
"Jerry Stuckle" <jstucklex@attglobal.net> escribió en el mensaje
news:jpj296$bh7$1@dont-email.me...
> On 5/23/2012 10:49 AM, Leonardo Azpurua wrote:
>> So, I must search an identifier in several associative arrays. And trying
>> to
>> access an array element with an invalid index triggers an error.
Hi,
I might have a valid index or not. And if it is valid, it could be valid on
one among several arrays.
Anyway, I just learnt that isset($arr[$ndx]) does not fire an error if $ndx
is not valid on $arr.
So, instead of
@$x = $arr[$ndx];
if (isset($x)) {
...
}
I should have written
if (isset($arr[$ndx])) {
$x = $arr[$ndx];
...
}
avoiding the rather ugly original construct.
Thanks!
--
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-05-23 16:14 -0400 |
| Message-ID | <jpjgg4$b97$2@dont-email.me> |
| In reply to | #6141 |
On 5/23/2012 2:45 PM, Leonardo Azpurua wrote:
> "Jerry Stuckle"<jstucklex@attglobal.net> escribió en el mensaje
> news:jpj296$bh7$1@dont-email.me...
>> On 5/23/2012 10:49 AM, Leonardo Azpurua wrote:
>>> So, I must search an identifier in several associative arrays. And trying
>>> to
>>> access an array element with an invalid index triggers an error.
>
> Hi,
>
> I might have a valid index or not. And if it is valid, it could be valid on
> one among several arrays.
>
> Anyway, I just learnt that isset($arr[$ndx]) does not fire an error if $ndx
> is not valid on $arr.
>
> So, instead of
>
> @$x = $arr[$ndx];
> if (isset($x)) {
> ...
> }
>
> I should have written
>
> if (isset($arr[$ndx])) {
> $x = $arr[$ndx];
> ...
> }
>
> avoiding the rather ugly original construct.
>
> Thanks!
> --
>
>
Yup, that's what isset() is for. And this way looks a lot nicer, also :)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Shake <QUITAESTO@QUITAESTO.NOES> |
|---|---|
| Date | 2012-05-23 16:12 +0200 |
| Message-ID | <jpir8f$til$1@dont-email.me> |
| In reply to | #6126 |
El 23/05/2012 15:17, Leonardo Azpurua escribió:
> Hi,
>
> A few weeks ago, I wrote this sentence:
>
> @$retVal = $this->lastfetch[$ndx];
>
> Yesterday, browsing the manual, I found this paragraph:
>
> "PHP supports one error control operator: the at sign (@). _When prepended
> to an expression_ in PHP, any error messages that might be generated by that
> expression will be ignored."
>
> and, a few lines further:
>
> "A simple rule of thumb is: if you can take the value of something, you can
> prepend the @ operator to it."
>
> Since an assigment is not an expression, the required syntax should be:
>
> $retVal = @$this->lastfetch[$ndx];
>
> But both forms work.
>
>
> Is there any reason to prefer one above the other?
>
Both forms works, but not both forms are the same:
$retVal = @$this->lastfetch[$ndx];
(....errors ignored....)
@$retVal = $this->lastfetch[$ndx];
(.........Errors ignored.........)
Perhaps in some cases "$retVal" could throw a type casting error or
something of this kind.
Rgds.
[toc] | [prev] | [next] | [standalone]
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Date | 2012-05-23 10:22 -0430 |
| Message-ID | <jpith6$c84$1@dont-email.me> |
| In reply to | #6128 |
"Shake" <QUITAESTO@QUITAESTO.NOES> escribió en el mensaje news:jpir8f$til$1@dont-email.me... > El 23/05/2012 15:17, Leonardo Azpurua escribió: >> Hi, >> >> A few weeks ago, I wrote this sentence: >> >> @$retVal = $this->lastfetch[$ndx]; >> >> Yesterday, browsing the manual, I found this paragraph: >> >> "PHP supports one error control operator: the at sign (@). _When >> prepended >> to an expression_ in PHP, any error messages that might be generated by >> that >> expression will be ignored." >> >> and, a few lines further: >> >> "A simple rule of thumb is: if you can take the value of something, you >> can >> prepend the @ operator to it." >> >> Since an assigment is not an expression, the required syntax should be: >> >> $retVal = @$this->lastfetch[$ndx]; >> >> But both forms work. >> >> >> Is there any reason to prefer one above the other? >> > > Both forms works, but not both forms are the same: > > > $retVal = @$this->lastfetch[$ndx]; > (....errors ignored....) > > @$retVal = $this->lastfetch[$ndx]; > (.........Errors ignored.........) > > > Perhaps in some cases "$retVal" could throw a type casting error or > something of this kind. Thanks. Is there any chance that a type casting error occurs in such a statement? --
[toc] | [prev] | [next] | [standalone]
| From | Shake <QUITAESTO@QUITAESTO.NOES> |
|---|---|
| Date | 2012-05-23 17:11 +0200 |
| Message-ID | <jpiuno$kih$1@dont-email.me> |
| In reply to | #6130 |
El 23/05/2012 16:52, Leonardo Azpurua escribió: >> >> Perhaps in some cases "$retVal" could throw a type casting error or >> something of this kind. > > Thanks. > > Is there any chance that a type casting error occurs in such a statement? > Don't know. Was only an Idea... a suspect, that that could happen (not necesarily with type casting). Rgds.
[toc] | [prev] | [next] | [standalone]
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Date | 2012-05-23 10:44 -0430 |
| Message-ID | <jpiuqc$l4b$1@dont-email.me> |
| In reply to | #6133 |
"Shake" <QUITAESTO@QUITAESTO.NOES> escribió en el mensaje news:jpiuno$kih$1@dont-email.me... > El 23/05/2012 16:52, Leonardo Azpurua escribió: >>> >>> Perhaps in some cases "$retVal" could throw a type casting error or >>> something of this kind. >> >> Thanks. >> >> Is there any chance that a type casting error occurs in such a statement? >> > > Don't know. Was only an Idea... a suspect, that that could happen (not > necesarily with type casting). Yup. Got the idea. Thanks, again.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-05-23 12:13 -0400 |
| Message-ID | <jpj2ai$bh7$2@dont-email.me> |
| In reply to | #6128 |
On 5/23/2012 10:12 AM, Shake wrote: > El 23/05/2012 15:17, Leonardo Azpurua escribió: >> Hi, >> >> A few weeks ago, I wrote this sentence: >> >> @$retVal = $this->lastfetch[$ndx]; >> >> Yesterday, browsing the manual, I found this paragraph: >> >> "PHP supports one error control operator: the at sign (@). _When >> prepended >> to an expression_ in PHP, any error messages that might be generated >> by that >> expression will be ignored." >> >> and, a few lines further: >> >> "A simple rule of thumb is: if you can take the value of something, >> you can >> prepend the @ operator to it." >> >> Since an assigment is not an expression, the required syntax should be: >> >> $retVal = @$this->lastfetch[$ndx]; >> >> But both forms work. >> >> >> Is there any reason to prefer one above the other? >> > > Both forms works, but not both forms are the same: > > > $retVal = @$this->lastfetch[$ndx]; > (....errors ignored....) > > @$retVal = $this->lastfetch[$ndx]; > (.........Errors ignored.........) > > > Perhaps in some cases "$retVal" could throw a type casting error or > something of this kind. > > Rgds. What type casting error? Or are you just guessing? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> |
|---|---|
| Date | 2012-05-24 22:26 +0200 |
| Message-ID | <jpm5hp$lkm$2@news.albasani.net> |
| In reply to | #6126 |
Leonardo Azpurua schrieb:
> Since an assigment is not an expression
But it is in PHP! You can write, e.g.:
if ( is_file( $file = $dir . $name . $ext ) )
{
include $file;
}
Greetings,
Thomas
--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web