Malhar Lathkar

Malhar Lathkar

103 Articles Published

Articles by Malhar Lathkar

Page 3 of 11

PHP CompileError

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 278 Views

IntroductionIn PHP 7.3 onwards, CompileError exception has been added. This class inherits Error class. Some error conditions that previously resulted in fatal error, now throw a CompileError. This affects compilation errors that are likely to be thrown by token_get_all() function.The token_get_all() function uses Zend lexical scanner to parse a given string into PHP language tokens.Syntaxtoken_get_all ( string $source [, int $flags = 0 ] ) : arrayParametersSr.NoParameter & Description1sourcePHP source to parse2flagTOKEN_PARSE - Recognises the ability to use reserved words in specific contexts.The function should be used in TOKEN_PARSE mode to be able to raise CompileError.

Read More

PHP DivisionByZeroError

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 2K+ Views

IntroductionDivisionByZeroError class is a subclass of ArithmeticError class. This type of error occurs when division operation involves value of denominator as zero. This can also occur when a modulo operator (%) has 0 as second operator, and intdiv() function having second argument as 0.DivisionByZeroError ExampleIn first example, we try to perform modulo division of 10 and 0 using % operator to induce DivisionByZeroError.Example Live DemoOutputThis will produce following result −Modulo by zeroIf call to intdiv() function with 0 as second argument also raises DivisionByZeroError as followsExample Live DemoOutputThis will produce following result −Division by zeroDivision operator (/) having 0 as denominator, however fails to raise error, ...

Read More

PHP ParseError

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 383 Views

IntroductionParseError class extends CompileError class. (Earlier it used to be subclass of Error class). This type of error is thrown while a PHP code inside a string that is given to eval() function as argument.The eval() function evaluates given string as PHP code.Syntaxeval ( string $code ) : mixedParametersSr.NoParameter & Description1codevalid PHP code to be evaluatedCode to be evaluated must not be embedded in PHP opening and closing tags and must be terminated by semicolon. Valide code retuns NULL whereas error in code throws ParseErrorFollowing example throws ParseError and is handled by catch blockExample Live DemoOutputThis will produce following result −Parse Error:syntax ...

Read More

PHP Types of Errors

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 466 Views

IntroductionPHP's internal Error types are represented by classes that are inherited from Error class. The Error class implements Throwable interface. Properties and methods of Error class are as follows −propertiesmessage − The error messagecode − The error codefile − The filename where the error happenedline − The line where the error happenedmethods__construct() − Construct the error objectgetMessage() − Gets the error messagegetPrevious() − Returns previous ThrowablegetCode() − Gets the error codegetFile() − Gets the file in which the error occurredgetLine() − Gets the line in which the error occurredgetTrace() − Gets the stack tracegetTraceAsString() − Gets the stack trace as ...

Read More

PHP Zip context options

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 284 Views

IntroductionPHP's ZIP extension registers zip:// wrapper. PHP 7.2.0 onwards supports passwords for encrypted archives. There is only one Zip context option called passwordExampleFirst create ZIP archive as follows:

Read More

PHP SSL context options

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 2K+ Views

IntroductionList of Context options for ssl:// and tls:// transports.peer_namePeer name to be used. If this value is not set, then the name is guessed based on the hostname used when opening the stream.verify_peerRequire verification of SSL certificate used. Defaults to TRUE.verify_peer_nameRequire verification of peer name. Defaults to TRUE.allow_self_signedAllow self-signed certificates. Requires verify_peer. Defaults to FALSEcafileLocation of Certificate Authority file on local filesystem to be used to authenticate identity of remote peer.capathmust be a correctly hashed certificate directory.local_certPath to local certificate file on filesystem.local_pkPath to local private key file on filesystem in case of separate files for certificate and private key.passphrasePassphrase with which ...

Read More

PHP Socket context options

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 407 Views

IntroductionAccess to filesystem and various other stream wrappers can be customized by various context options and parameters configures by stream_context_create() and stream_context_set_option() functions.Following list shows various socket context options are available for all wrappers that work over sockets, like tcp, http and ftp.bindtospecifies the IP address (either IPv4 or IPv6) and/or the port number used to access the network. (ip:port for IPv4 [ip]:port for IPv6).backloglimits number of outstanding connections in socket's listen queue.ipv6_v6onlyOverrides the OS default regarding mapping IPv4 into IPv6.so_reuseportAllows multiple bindings to a same ip:port pair.so_broadcastEnables sending and receiving data to/from broadcast addresses.tcp_nodelayIf TRUE, sets SOL_TCP, NO_DELAY=1 appropriately, disabling ...

Read More

PHP Phar context options

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 233 Views

IntroductionPhar stands for PHP Archive. All the resources of a certain PHP application or library are packages in a single .phar file for the purpose of istribution. A phar file can be used as IO stream with phar:// wrapper. Context options for phar:// wrapper are listed as follows −compressPHP has following predefined constants for defining compression formatsConstantValueDescriptionPhar::NONE0x00000000no compressionPhar::COMPRESSED0x0000F000bitmask with file flags to determine if any compression is presenPhar::GZ0x00001000zlib (gzip) compressionPhar::BZ20x00002000bzip2 compressionmetadataAny PHP variable containing information to store that describes the phar archive is used as argument for Phar::setMetadata() methodExampleThis example Phar context option set for creating Phar file

Read More

PHP Context Parameters

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 570 Views

IntroductionContext parameters allow customization of access to filesystem and other stream wrappers. To configure a stream, PHP has stream_context_set_params() function.Syntaxstream_context_set_params ( resource $stream_or_context , array $params ) : bool$stream_or_context can be any of PHP's supported streams/wrappers/contexts$params is an array with following properties. should be an associative array of the structure − $params['paramname'] = "paramvalue";context parametersnotification − A user-defined callback to be called whenever a stream triggers a notification. Only for http:// and ftp:// stream wrappers.The notification callback function has following syntaxsyntaxstream_notification_callback ( int $notification_code , int $severity , string $message , int $message_code , int $bytes_transferred , int $bytes_max ) ...

Read More

PHP MongoDB context options

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 221 Views

IntroductionPHP can interact with MongoDB database through database extensions. For older versions of PHP, mongo driver can be installed from PECL. This has now been replaced by mongodb driver. Both drivers can be installed using precompiled binaries for Linux/Windows/MacOS operating systems. Alternately, manual installation can be done from source tarball available on github. In either case, mongo or mongodb extension should be enabled in php.ini settings.The PHP MongoDB extension provides Stream Context Support using the mongodb context. Relevent context options are as followsOptionslog_cmd_insert ( array $server , array $document , array $writeOptions , array $protocolOptions )This is a callable function, used ...

Read More
Showing 21–30 of 103 articles
« Prev 1 2 3 4 5 11 Next »
Advertisements