PHP basic OOP from Exception to Reflection

Choirul Anam
3 min readApr 9, 2022

--

Learning from Udemy

Photo by Luca Bravo on Unsplash

Assalamualaikum warrahmatullahi wabarakatuh.

Exception

When we create an application we will not be spared by the name error in PHP errors are represented by the term exception and all are represented in the form of an exception class. we can use the exception class itself or use the one provided by PHP if we want to make an exception then we must create a class that implements the Throwable interface or its derivatives.

how to make exception. exceptions usually occur in a function, in our program code to create an exception we simply use the throw keyword followed by the exception object.

try Error username and password is null

Try Catch
when we call a function that can cause an exception, it is recommended that we use a try-catch expression in PHP, so that we can catch the exception that occurs because if it is not caught then an exception occurs.
then our program will automatically stop, how to use a try-catch expression in PHP is very easy, in the try block we just call the method that can cause an exception and in the catch block we can do something if an exception occurs.

multiply try catch

or ca use multiply try catch this one

Finally Keyword
in the try-catch we can add a finally block, this block is a block which will always be executed whether an exceptional occurs or not. This is very suitable when we want to do something no matter whether it succeeds or fails, for example in the try block we want to read a file, we must close the connection to the file so it doesn’t hang in memory.

Regular Expression

Reflection
reflection is reading the code structure while the application is running, reflection is a very long and a lot of material
So here we will only discuss the introduction
reflection is a feature that is usually used when we create a framework.

reflection

thats for today. Thanks

Wassalamualaikum warrahmatullahi wabarakatuh.

--

--

Choirul Anam
Choirul Anam

No responses yet