Vinay Jeurkar
Vinay Jeurkar

Reputation: 3122

PHP $_GET['myval'] Help needed

What does following statement means

$tmp = @$_GET['myValue'];

Can somebody please provide detailed explanation on above statement?

Upvotes: 0

Views: 286

Answers (4)

Pramendra Gupta
Pramendra Gupta

Reputation: 14873

@ :  to avoid warning 

$_GET : An associative array of variables passed to the current script via the URL parameters.

myval : parameter

--

example

http://example.com/?myval=test
echo @$_GET['myval']; will echo test

http://example.com/
echo @$_GET['myval']; will be null
//php 5.4 way is
var_dump(isset($_GET['myValue']) ? : null);

Upvotes: 0

Sparky
Sparky

Reputation: 4879

The @ symbol is an error suppressor operator. It is not recommended to use it everywhere. Also, it is twice slower than the isset() function. See full reference for the @ error control operator at http://php.net/manual/en/language.operators.errorcontrol.php

Upvotes: 3

Matt Bishop
Matt Bishop

Reputation: 1007

Please see the documentation and examples here.

Upvotes: 2

zerkms
zerkms

Reputation: 255015

It assigns value of GET parameter myValue into tmp if exists. If not - then tmp = null

PS: it is a bad practice. Better way to do the same is:

$tmp = isset($_GET['myValue']) ? $_GET['myValue'] : null;

Upvotes: 1

Related Questions