Learn How to Remove Old Extensions, SAPIs, Added New Classes and Interfaces

0
1065
Old Extensions

Old Extensions

In the last chapter, we discussed the various PHP features that are deprecated in PHP 7 release along with examples. In this chapter, we are going to discuss the various old extensions and SAPIs which are removed in PHP 7. Also, the new classes and interfaces which are added to PHP 7 along with an example.

Following are the extensions which have been removed from PHP 7 onwards.

  • ereg

  • mssql

  • mysql

  • sybase_ct

SAPIs (server application programming interfaces) are the direct module interface extended to the web servers like Apache HTTP Server, etc. In other words, these are the APIs which are provided by the various web server to help the developers in the extension of their capabilities. Following are the SAPIs which have been removed from PHP 7 onwards.

  • aolserver

  • apache

  • apache_hooks

  • apache2filter

  • caudium

  • continuity

  • isapi

  • milter

  • nsapi

  • phttpd

  • pi3web

  • roxen

  • thttpd

  • tux

  • webjames

PHP 7 new classes and interfaces

Following are the new classes and interfaces which are added to the PHP 7.0.x.

  • Intl

  1. IntlChar: We have already discussed about this class in chapter 7 of this tutorial series. This particular class exposes additional ICU functionality. It has a number of constants and utility methods that can be used to access information and manipulate Unicode characters. These constants and methods resemble the names and behavior used by the underlying ICU library.

  • Reflection

  1. ReflectionGenerator: The ReflectionGenerator class helps in reporting the information about a generator.

Table of Content for utility methods present in ReflectionGenerator class

S No.

Methods present in ReflectionGenerator class

Implementation in PHP 7 Program

Description

1.public __construct ( Generator $generator )ReflectionGenerator::__construct

This method is used to construct a ReflectionGenerator object.

2.public string getExecutingFile ( void )ReflectionGenerator::getExecutingFile

This method is used to get the file name of currently executing generator.

3.public Generator getExecutingGenerator ( void )ReflectionGenerator::getExecutingGenerator

This method is used to get the executing Generator object.

4.public int getExecutingLine ( void )ReflectionGenerator::getExecutingLine

This method is used to get the currently executing line of the generator.

5.public ReflectionFunctionAbstract getFunction ( void )ReflectionGenerator::getFunction

This method is used to get the function name of the generator.

6.public object getThis ( void )ReflectionGenerator::getThis

This method is used to get the $this value of the generator.

7.public array getTrace ([ int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT ] )ReflectionGenerator::getTrace

This method is used to get the trace of the executing generator.

  1. ReflectionType: The ReflectionType class helps in reporting the information about a function’s return type.

Table of Content for utility methods present in ReflectionType class

S No.

Methods present in ReflectionType class

Implementation in PHP 7 Program

Description

1.public bool allowsNull ( void )ReflectionType::allowsNull

This method is used to check if null is allowed.

2.public bool isBuiltin ( void )ReflectionType::isBuiltin

This method is used to check if it is a built-in type

3.public string __toString ( void )ReflectionType::__toString

To string.

  • Session Handling

  1. SessionUpdateTimestampHandlerInterface: It is an interface introduced in PHP 7 that helps in handling session update timestamp in PHP sessions.

  • Exception Hierarchy

  1. Throwable: It is an interface to an object that is thrown by using the throw statement. It includes both exceptions and errors. Following are the list of methods with which we can use as Throwable.

S No.

Methods present in Throwable interface

Implementation in PHP 7 Program

Description

1.abstract public string __toString ( void )

Throwable::__toString

This method will return string representation of thrown object.

2.abstract public Throwable getPrevious ( void )

Throwable::getPrevious

This method is used to return the previous Throwable

3.abstract public string getTraceAsString ( void )

Throwable::getTraceAsString

This method will return the stack trace in form of string.

4.abstract public array getTrace ( void )

Throwable::getTrace

This method will return the stack trace.

5.abstract public int getLine ( void )

Throwable::getLine

This method will return the line where object was instantiated.

6.abstract public string getFile ( void )

Throwable::getFile

This method will return the file where exception occurred.

7.abstract public int getCode ( void )

Throwable::getCode

This method will return exception code.

8.abstract public string getMessage ( void )

Throwable::getMessage

This method will return the message

  1. Error: Error is the base class of all PHP all errors. Following are the list of methods present in error class.

S No.

Methods present in Error class

Implementation in PHP 7 Program

Description

1.final public mixed getCode ( void )Error::getCode

This method will return the code of error.

2.final public Throwable getPrevious ( void )Error::getPrevious

This method will return the last Throwable.

3.final public string getMessage ( void )Error::getMessage

This method will return the error message.

4.public __construct ([ string $message = “” [, int $code = 0 [, Throwable $previous = NULL ]]] )

Error::__construct

This method is used to construct error object.

5.final public string getTraceAsString ( void )

Error::getTraceAsString

This method will return the stack trace as string.

6.final public array getTrace ( void )

Error::getTrace

This method will return the stack trace.

7.final public int getLine ( void )

Error::getLine

This method will return the line where error has occurred.

8.public string __toString ( void )

Error::__toString

This method is used for string representation of error.

9.final private void __clone ( void )

Error::__clone

This method is used for cloning of error

10.final public string getFile ( void )

Error::getFile

It will return that file due to which the error has occurred.

  1. TypeError: This class extends Error class. We will observe this type of error as a result for the following 3 scenarios:

  • If we have passed an invalid number of arguments to a PHP function.

  • If we have declared a function where the return type does not match the type of value returned by that function.

  • If we have passed argument type that is mismatched with the declared parameter type

  1. ParseError: This class extends Error class. Parse error occurs as a result of parsing when function eval () is called.

  2. AssertionError: This class extends Error class. We will observe this type of error in PHP 7 as the result of assertion through assert () failure.

  3. ArithmeticError: This class extends Error class. This error will occur as a result of any attempt to perform a bit shift by negative amount or may be due to call to indiv (), which will ultimately result in value other than the boundaries defined for the integer.

  4. DivisionByZeroError: This class extends ArithmeticError class. We will observe this type of error in PHP 7 when our PHP code will make an attempt to divide a number by 0.

Conclusion

In this chapter, we have discussed the various old extensions and SAPIs which are removed in PHP 7 and the new classes and interfaces which are added to PHP 7 as oppose to PHP 4 and 5.x. In the upcoming chapter, we are going to discuss about the Generator Return Expressions and Delegation which are added to PHP 7.

LEAVE A REPLY

Please enter your comment!
Please enter your name here