I know that we use GET function to get the variables from the url in php when we use the GET method to pass data across pages or within the same page.
However
$obj = new BlahBlahName($_GET);
what does this do?
In order to understand this, you should understand what is the "$_GET" variable. To get full information about it, you can read the official PHP.net documentation on it. Here is the link: http://php.net/manual/en/reserved.variables.get.php
Here is the information summarized. Basically whenever a page loads and has some variables are defined in it's address, PHP generates an array variable named $_GET. So, this variable is nothing more than an array. For example, if the page with the following address would be loaded: www.example.com?var1=val1&var2=val2, the $_GET array would look something like this:
{
'var1' => 'val1',
'var2' => 'val2'
}
So, since the $_GET is an array, you can apply different functions to it. You can check if this variable/array has been defined already isset($_GET), count how many elements are in it count($_GET), and so on. None of these function will actually have to look at the specific values of the array like $_GET["var1"], but look at the array in general.
In your example, $_GET is passed into not just any function but to a class when an instance of it is initialized. Whenever a class object is created, a certain function is called named constructor. So, this $_GET array is simply passed into this constructor function. To read more about constructors, you can go here: http://php.net/manual/en/language.oop5.decon.php.
Hope this helps.
It simply passes the $_GET
array to to the BlahBlahName
constructor. The constructor might pull whatever it needs from the array when creating the BlahBlahName
object.
$_GET
is not a function; rather, it is an associative array of variables provided in the request. For some reason w3schools calls it a function; this seems misleading.*
Have a look at the actual code for the BlahBlahName
__construct()
function (if you can) to see exactly what it's doing with the variable if you're curious.
* W3schools has since updated their description of $_GET
It creates a new BlahBlahName object using the $_GET array. The constructor probably parses the values in the array and assigns them to BlahBlahName properties.
That calls the constructor for BlahBlahName
with passing $_GET
and assigns it to $obj
.
It would pass the array $_GET to the constructor of the BlahBlahName class. $_GET is an array of variables passed in the URL.
new BlahBlahName will return a new instance of an object/class to the $obj variable. From this you will be able to call methods from the class, e.g. $obj->method(). The class in question which it will use will be BlahBlahName.
In your code, you are passing through the $_GET array into the classes constructor, which is essentially pointless because $_GET is a superglobal and should be available throughout your code.
It's most likely a filter object wrapping the PHP input arrays. I'm using something similar:
$_REQUEST = new input($_REQUEST);
It basically captures the former $_REQUEST
array and makes it an object property. Object-oriented superglobals