Malhar Lathkar has Published 155 Articles

PHP Name Resolution Rules

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:33:15

154 Views

IntroductionIn a PHP code, appearance of namespace is resolved subject to following rules −A namespace identifier without namespace separator symbol (/) means it is referring to current namespace. This is an unqualified name.If it contains separator symbol as in myspace\space1, it resolves to a subnamespace space1 under myspace. Such type ... Read More

PHP Defining Multiple Namespaces in same file

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:29:16

478 Views

IntroductionMore than one namespaces can be defined in a single file with .php extension. There are two diferent methods prescribed for the purpose. combination syntax and bracketed syntaxMultiple Namespaces with Combination SyntaxIn this example two namespaces are defined one below the other. Resources in first namespace are available till second ... Read More

PHP Aliasing/Importing namespaces

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:27:25

714 Views

IntroductionAn important feature of namespaces is the ability to refer to an external fully qualified name with an alias, or importing. PHP namespaces support following kinds of aliasing or importing −aliasing a class name, aliasing an interface name, aliasing a namespace namealiasing or importing function and constant names.In PHP, aliasing ... Read More

PHP Accessing Global classes

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:25:03

252 Views

IntroductionWhen PHP parser encounters an unqulified identifier such as class or function name, it resolves to current namespace. Therefore, to access PHP's predefined classes, they must be referred to by their fully qualified name by prefixing \.Using built-in classIn following example, a new class uses predefined stdClass as base class. ... Read More

PHP Global space

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:23:08

184 Views

IntroductionIn absence of any namespace definition, all definitions of class, function etc. are placed in a global namespace. If a name is prefixed with \ , it will mean that the name is required from the global space even in the context of the namespace.Using global space specificationExampleIncluded files will default ... Read More

PHP Defining namespace

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:21:16

119 Views

IntroductionDeclaration of class, function and constants inside a namespace affects its acess, although any other PHP code can be present in it. PHP's namespace keyword is used to declare a new namespace. A file with .php extension must have namespace declaration in very first line after If namespace declaration is not ... Read More

PHP namespace keyword and __NAMESPACE__ constant

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:19:17

311 Views

IntroductionIn PHP, namespace keyword is used to define a namespace. It is also used as an operator to request access to certain element in current namespace. The __NAMESPACE__ constant returns name of current namespace__NAMESPACE ConstantFrom a named namespace, __NAMESPACE__ returns its name, for global and un-named namespace it returns empty striingExample Live ... Read More

PHP Generators.

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:15:49

2K+ Views

IntroductionTraversing a big collection of data using looping construct such as foreach would require large memory and considerable processing time. With generators it is possible to iterate over a set of data without these overheads. A generator function is similar to a normal function. However, instead of return statement in ... Read More

PHP Generators vs Iterator objects

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:12:48

424 Views

IntroductionWhen a generator function is called, internally, a new object of Generator class is returned. It implements the Iterator interface. The iterator interface defines following abstract methodsIterator::current — Return the current elementIterator::key — Return the key of the current elementIterator::next — Move forward to next elementIterator::rewind — Rewind the Iterator to the ... Read More

PHP Throwing Exceptions

Malhar Lathkar

Malhar Lathkar

Updated on 18-Sep-2020 09:10:58

257 Views

IntroductionThrowable interface is implemented by Error and Exception class. All predefined Error classes are inherited from Error class. Instance of corresponding Error class is thrown inside try block and processed inside appropriate catch block.Throwing ErrorNormal execution (when no exception is thrown within the try block) will continue after that last ... Read More

Advertisements