Jump to content

Quick And Easy Function Question


phprocker

Recommended Posts

It is to indicate that the variable is being passed by reference rather than by value. Basically the function is passed the memory address of the variable in the servers' RAM and adding another 'name' by which to access it in the file table.

This way when the function updates the variable in the functions' scope and passes back to the local scope in which the function was called, the modifications to the referenced variable are still in effect.

Heres an example you can run to get an idea of how it works. It also uses recursion. 

<?php

function incrementToTen( & $i )

{

   if ( !is_int($i) ) return;

   if ( $i < 10 )

   {

      echo 'i = ' . ++$i . '<br >';

      incrementToTen($i);

   }

}

$n = 0;

incrementToTen($n);

echo '<br >n = ' . $n;
?>

 

The @ symbol is used to suppress errors so they don't display, although it is normally before a call is made to a built in php function that you see the @ symbol. I have never seen it used in the context of your example.

 

 

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

 

// EDIT: now I have

 

In the comments on the above link.

 

/*
dsbeam at gmail dot com
02-Sep-2009 02:22 

Though error suppression can be dangerous at times, it can be useful as well.  I've found the following statements roughly equivalent:
*/

     if( isset( $var ) && $var === $something )
     if( @$var === $something )

/*
EXCEPT when you're comparing against a boolean value (when $something is false).  In that case, if it's not set the conditional will still be triggered.

I've found this useful when I want to check a value that might not exist:
*/
     if( @$_SERVER[ 'HTTP_REFERER' ] !== '/www/some/path/file' )

// or when we want to see if a checkbox / radio button have been submitted with a post action

     if( @$_POST[ 'checkbox' ] === 'yes' )

// Just letting you guys know my findings, 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.