I have a couple questions about one of the pages I am trying to rewrite.

As an example I have "magic_quotes" and need to find an alternative to them.

$PHP = explode( ".", phpversion( ) );
$g['php'] = $PHP[0];
$g['php2'] = $PHP[1];
if ( $g['php'] == 5 && function_exists( "date_default_timezone_set" ) )
{
    @date_default_timezone_set( @date_default_timezone_get( ) );
}
set_magic_quotes_runtime( false );
if ( !isset( $g['to_root'] ) )
{
    $g['to_root'] = "../";
}

Another line using magic quotes:

@set_magic_quotes_runtime( @false );
include_once( $g['to_root']."_include/lib/lib.php" );
if ( !null !==( $g['error_output'] ) )
{
    $g['error_output'] = "browser";
}
error_reporting( E_ALL );

I am aware the magic_quotes have been removed, but I need to work around this type of scenario when I find them within this code.

I also have a question about "isset" which is also deprecated. I have found that changing it to use "null !==" is its placement according to the php manual, but what I am trying to learn is the following.

if ( !isset( $g['error_output'] ) )

If there is an exclamation "!" before the instruction, what is it stating? From what I have been reading it is a logical "NOT" operator so which should return a the reverse of the equations function. If True, then show false and vise versa. Is this correct?

The other side to this is how do I write the line without the !isset to get the same function. Surely ! null !== is not the correct structure to do this.

    Since magic_quotes has been removed, it is implicitly always FALSE (and hence doesn't need to be set to false; setting it to false has no effect).

    [man]isset[/man] is not deprecated.

      My error regarding "isset", I had thought I read that isset is no longer used. In fact it is the debugger(PhpEd), that has flagged the error... but not the instruction being deprecated.

      It is stating "Cannot use isset() on the result of an expression (you can use "null !==expression" instead).

      error_reporting( E_ALL );
      ini_set( "display_errors", 1 );
      if ( isset( "_REQUEST" ) )
      {
          foreach ( $_REQUEST as $key => $value )
          {
          }
      }

      So in this example, can isset remain or should it be rewritten to use the "null !==" instruction?

      Or would this line be correct?

      error_reporting( E_ALL );
      ini_set( "display_errors", 1 );
      if ( null !==( "_REQUEST" ) )
      {
          foreach ( $_REQUEST as $key => $value )
          {
          }
      }

      With the "magic_quotes", I have different lines using various magic quotes, get_magic_quote, set_magic_quote and a couple others. If the instruction is no longer used... the preceding lines of instruction would need to have some type of replacement instruction to complete the procedure wouldn't it?

        isset( "_REQUEST" )

        Isset is to be used on variables, not expressions (if the error message had been because it was deprecated, it would have said so). [font=monospace]"_REQUEST"[/font] is a string. You probably mean [font=monospace]$_REQUEST[/font].

        If the instruction is no longer used... the preceding lines of instruction would need to have some type of replacement instruction to complete the procedure wouldn't it?

        No, you just remove those lines. The functionality no longer exists so no you longer need to turn it off.

          Weedpacket;11052555 wrote:

          No, you just remove those lines. The functionality no longer exists so no you longer need to turn it off.

          Should we make assumptions about versioning?

          if ( $g['php2'] < 3 ) {
             set_magic_quotes_runtime( false ); 
          }

          ?

            dalecosp;11052557 wrote:

            Should we make assumptions about versioning?

            if ( $g['php2'] < 3 ) {
               set_magic_quotes_runtime( false ); 
            }

            ?

            And what if you're running 7.0.0 which is now GA? Instead, better to use [man]version_compare[/man]

            if (version_compare(phpversion(), '5.3.0', '<')) {
               set_magic_quotes_runtime(false);
            }
            

              I thought about that, but the context is upgrading to 5.6.

                Write a Reply...