Jump to content

Recommended Posts

Judging from those errors you are not placing quotes around strings as indexes in your arrays.

 

This is the correct way:

$myArray['myIndex']

 

This is not *:

$myArray[myIndex]

 

* Unless you already have a constant defined called myIndex

 

That is what this error means:

Use of undefined constant language - assumed 'language' (error type 8 in /home/steviez/YC9R5F01/htdocs/music4play/connect on line 26) [context: Array]

Undefined index: language (error type 8 in /home/steviez/YC9R5F01/htdocs/music4play/connect on line 26) [context: Array]

 

When you don't place quotes around letters that are supposed to be strings PHP will assume you are using a constant (a constant is a bit like a variable except you cant change its value and you don't need the $ sign at the start). However PHP is smart to enough to correct you but will then give you a notice message - which what most of those errors are.

Link to comment
https://forums.phpfreaks.com/topic/39988-solved-help-me/#findComment-193682
Share on other sites

Thanks for your reply, i will look in to this and see if your right about my code, just incase its needed here is the code for my error class:

 

<?php

class clsErrorHandle
{
  /**
  * The filename of the log file.
  *
  * NOTE: $error_log_filename will only be used if you have log_errors Off and ;error_log filename in php.ini
  * if log_errors is On, and error_log is set, the filename in error_log will be used.
  *
  * @var string
  * @access public
  */
  var $error_log_filename;
  /**
  * The recipient email to mail errors to
  *
  * @var string
  * @access public
  */
  var $to;
  /**
  * Holds the total error report to be used by mailError()
  *
  * @var string
  * @access public
  */
  var $mail_buffer;
  /**
  * The flag that determines whether or not errors will be logged to the error file.
  *
  * @var Boolean
  * @access public
  * @see $LOG_WARNINGS_TO_FILE
  * @see $LOG_NOTICES_TO_FILE
  */
  var $LOG_ERRORS_TO_FILE;
  /**
  * The flag that determines whether or not warnings will be logged to the error file.
  *
  * @var Boolean
  * @access public
  * @see $LOG_ERRORS_TO_FILE
  * @see $LOG_NOTICES_TO_FILE
  */
  var $LOG_WARNINGS_TO_FILE;
  /**
  * The flag that determines whether or not notices will be logged to the error file.
  *
  * @var Boolean
  * @access public
  * @see $LOG_ERRORS_TO_FILE
  * @see $LOG_WARNINGS_TO_FILE
  */
  var $LOG_NOTICES_TO_FILE;
  /**
  * Send errors via email?
  *
  * @var Boolean
  * @access public
  * @see $SEND_WARNINGS_TO_MAIL;
  * @see $SEND_NOTICES_TO_MAIL;
  */
  var $SEND_ERRORS_TO_MAIL;
  /**
  * Send warnings via email?
  *
  * @var Boolean
  * @access public
  * @see $SEND_ERRORS_TO_MAIL;
  * @see $SEND_NOTICES_TO_MAIL;
  */
  var $SEND_WARNINGS_TO_MAIL;
  /**
  * Send notices via email?
  *
  * @var Boolean
  * @access public
  * @see $SEND_ERRORS_TO_MAIL;
  * @see $SEND_WARNINGS_TO_MAIL
  */
  var $SEND_NOTICES_TO_MAIL;
  /**
  * clsErrorHandle::clsErrorHandle
  *
  * @return void
  * @access public
  */
  function clsErrorHandle()
  { 
      $this->sendMailTo( 'recipient', '[email protected]' );
      $this->setFilename( '/home/steviez/YC9R5F01/htdocs/xxxx/include/logs/Error_log.log' );
    $this->setFlags();
    set_error_handler( array( &$this, 'ERROR_HANDLER' ) );
    register_shutdown_function( array( &$this, 'clsErrorHandleDestruct' ) );
  } //END OF ErrorHandle()
  function clsErrorHandleDestruct()
  {
      if( strlen( $this->mail_buffer ) > 0 )
      {
          $this->mailError( $this->mail_buffer ); //Send the email
      }
  }
  /**
  * The error handling routine set by set_error_handler()
  *
  * @param string $error_type The type of error being handled.
  * @param string $error_msg The error message being handled.
  * @param string $error_file The file in which the error occurred.
  * @param integer $error_line The line in which the error occurred.
  * @param string $error_context The context in which the error occurred.
  * @return Boolean
  * @access public
  * @see clsErrorHandle()
  */
  function ERROR_HANDLER($error_type, $error_msg, $error_file, $error_line, $error_context)
  {
   switch( $error_type )
   {
     case E_ERROR:
     case E_USER_ERROR:
     if( $this->LOG_ERRORS_TO_FILE )
     {
       if( $this->error_log_filename == '' )
       {
         error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 0);
       } else  {
         error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 3, $this->error_log_filename);
       }
     }
     if( $this->SEND_ERRORS_TO_MAIL )
     {
         $this->mail_buffer .= $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10);
     }
     echo $error_msg,' (error type ',$error_type,' in ',$error_file,' on line ',$error_line,') [context: ',$error_context,']<br />';
     exit;
     break;
     case E_WARNING:
     case E_USER_WARNING:
     if( $this->LOG_WARNINGS_TO_FILE )
     {
       if( $this->error_log_filename == '' )
       {
         error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 0);
       } else  {
         error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 3, $this->error_log_filename);
       }
     }
     if( $this->SEND_WARNINGS_TO_MAIL )
     {
         $this->mail_buffer .= $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10);
     }
     echo $error_msg,' (error type ',$error_type,' in ',$error_file,' on line ',$error_line,') [context: ',$error_context,']<br />';
     break;
     case E_NOTICE:
     case E_USER_NOTICE:
     if( $this->LOG_NOTICES_TO_FILE )
     {
       if( $this->error_log_filename == '' )
       {
         error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 0);
       } else  {
         error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 3, $this->error_log_filename);
       }
     }
     if( $this->SEND_NOTICES_TO_MAIL )
     {
         $this->mail_buffer .= $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10);
     }
     echo $error_msg,' (error type ',$error_type,' in ',$error_file,' on line ',$error_line,') [context: ',$error_context,']<br />';
     break;
   }
   return true;
  } //END OF ERROR_HANDLER()
  /**
  * Method that changes the filename of the generated log file.
  *
  * @param string $filename The filename to be used for the log file.
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function setFilename( $filename )
  {
      $this->error_log_filename = $filename; //Error Log Filename
  }//END OF setFilename()
  /**
  * Method that changes the logging flags..
  *
  * @param Boolean $error_flag Log errors to file?
  * @param Boolean $warning_flag Log warnings to file?
  * @param Boolean $notice_flag Log notices to file?
  * @param Boolean $error_mailflag Send errors via mail?
  * @param Boolean $warning_mailflag Send warnings via mail?
  * @param Boolean $notice_mailflag Send notices via mail?
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function setFlags( $error_flag = true, $warning_flag = true, $notice_flag = true, $error_mailflag = true, $warning_mailflag = true, $notice_mailflag = true )
  {
      $this->LOG_ERRORS_TO_FILE = $error_flag;           //Log errors to file?
    $this->LOG_WARNINGS_TO_FILE = $warning_flag;          //Log warnings to file?
    $this->LOG_NOTICES_TO_FILE = $notice_flag;           //Log notices to file?
    $this->SEND_ERRORS_TO_MAIL = $error_mailflag;       //Send errors via mail?
    $this->SEND_WARNINGS_TO_MAIL = $warning_mailflag;   //Send warnings via mail?
    $this->SEND_NOTICES_TO_MAIL = $notice_mailflag;     //Send notices via mail?
  }//END OF setFlags()
  /**
  * Method that restores the error handler to the default error handler
  *
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function restoreHandler()
  {
      restore_error_handler();
  }
  /**
  * Method that returns the error handler to ERROR_HANDLER()
  *
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function returnHandler()
  {
    set_error_handler( array( &$this, 'ERROR_HANDLER' ) );
  }
  /**
  * This will print the associative array populated by backtrace data
  *
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function showBacktrace()
  {
      debug_print_backtrace();
  }
  /**
  * Method that is used to send error reports via email
  *
  * @param string $mail_body Error message
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function mailError( $mail_body )
  {
    $headers ='From: clsErrorHandler' . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
    $subject = 'Error Report';
    $body = $mail_body;
    mail( $this->to, $subject, $body, $headers );
  }
  /**
  * This method will setup php to send mail via mail() on a Windows server
  *
  * @param string $smtp_server Your SMTP Server address
  * @param string $sendmail_from Your email address
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function setupWinMail( $smtp_server, $sendmail_from )
  {
      ini_set( 'SMTP', $smtp_server );
      ini_set( 'sendmail_from', $sendmail_from );
  }
  /**
  * This method will setup php to send mail via mail() on a Linux server
  *
  * Usually /usr/bin/sendmail
  *
  * @param string $sendmailpath Path to sendmail on your server, and whatever flags you wish to use with sendmail.
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function setupLinMail( $sendmailpath )
  {
      ini_set( 'sendmail_path', $sendmailpath );
  }
  /**
  * This method will set which email address error reports are sent to.
  *
  * @param string $recipient_name The name of the recipient.
  * @param string $recipient_address The email address of the recipient.
  * @return void
  * @access public
  * @see clsErrorHandle()
  */
  function sendMailTo( $recipient_name, $recipient_address )
  {
    $this->to = $recipient_name . ' <'. $recipient_address .'>';
  }

}
?> 

Link to comment
https://forums.phpfreaks.com/topic/39988-solved-help-me/#findComment-193712
Share on other sites

I never had any faults with my pages untill i installed this class, although i guess thats what its for, finding errors that may not otherwise show up. Im going to go through all the faults when i get some time this week then i will post my results or questions backup here. Thanks guys for the help so far!

 

Steve

Link to comment
https://forums.phpfreaks.com/topic/39988-solved-help-me/#findComment-193758
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.