We are independent & ad-supported. We may earn a commission for purchases made through our links.

Advertiser Disclosure

Our website is an independent, advertising-supported platform. We provide our content free of charge to our readers, and to keep it that way, we rely on revenue generated through advertisements and affiliate partnerships. This means that when you click on certain links on our site and make a purchase, we may earn a commission. Learn more.

How We Make Money

We sustain our operations through affiliate commissions and advertising. If you click on an affiliate link and make a purchase, we may receive a commission from the merchant at no additional cost to you. We also display advertisements on our website, which help generate revenue to support our work and keep our content free for readers. Our editorial team operates independently from our advertising and affiliate partnerships to ensure that our content remains unbiased and focused on providing you with the best information and recommendations based on thorough research and honest evaluations. To remain transparent, we’ve provided a list of our current affiliate partners here.

What Is an Abstract Class in PHP?

By Alex Newth
Updated Feb 17, 2024
Our promise to you
WiseGeek is dedicated to creating trustworthy, high-quality content that always prioritizes transparency, integrity, and inclusivity above all else. Our ensure that our content creation and review process includes rigorous fact-checking, evidence-based, and continual updates to ensure accuracy and reliability.

Our Promise to you

Founded in 2002, our company has been a trusted resource for readers seeking informative and engaging content. Our dedication to quality remains unwavering—and will never change. We follow a strict editorial policy, ensuring that our content is authored by highly qualified professionals and edited by subject matter experts. This guarantees that everything we publish is objective, accurate, and trustworthy.

Over the years, we've refined our approach to cover a wide range of topics, providing readers with reliable and practical advice to enhance their knowledge and skills. That's why millions of readers turn to us each year. Join us in celebrating the joy of learning, guided by standards you can trust.

Editorial Standards

At WiseGeek, we are committed to creating content that you can trust. Our editorial process is designed to ensure that every piece of content we publish is accurate, reliable, and informative.

Our team of experienced writers and editors follows a strict set of guidelines to ensure the highest quality content. We conduct thorough research, fact-check all information, and rely on credible sources to back up our claims. Our content is reviewed by subject matter experts to ensure accuracy and clarity.

We believe in transparency and maintain editorial independence from our advertisers. Our team does not receive direct compensation from advertisers, allowing us to create unbiased content that prioritizes your interests.

Hypertext Preprocessor (PHP) is a scripting language that serves as an all-purpose language primarily employed on websites; it talks to databases, creates special effects and logic, and helps with administrative functions such as managing website members. The class code in PHP is used to make a capsule of coding that can be used continuously, so the programmer does not need to write the same coding for each instance. The abstract class in PHP, which was introduced with PHP5, is similar to the regular class but is used when only some of the class’s code will be needed, while other sections will need to be defined for the specific usage to work correctly. The abstract class in PHP can be set as public or protected, but not private.

The way a general class works in PHP is the programmer gives the class a title — such as “vehicle” if the coding is for a vehicle — that can be recalled later. Within this class, the programmer will write a set of instructions, such as code to make a vehicle turn left or brake. This type of coding emulates object-oriented coding, or coding that separates parts of the code into objects that have their own sets of code. PHP is not naturally an object-oriented code but, through this method, can emulate it.

An abstract class in PHP is built in a similar way. The main difference in the coding with an abstract class in PHP is that the class structure starts with “abstract class” instead of “class.” When this code is made, it creates an incomplete guide for the program to look at; the incomplete guide can then be filled in later.

The incomplete portions are filled in when the abstract class is called during the program. For example, the vehicle abstract class will have basic instructions that work with all types of vehicles, such as cars, trucks and motorcycles. Each vehicle, though, has its own specific needs, and the abstract class will allow the programmer to fill in these specific needs without having to write separate coding for each vehicle. This makes coding more time efficient, minimizes mistakes and makes it easier to make quick changes to every object that uses the abstract class.

PHP classes are specified as public, protected or private. Each of these labels acts as a shield that limits visibility of the code according to a user’s access level. Setting a class as public allows any user to see the code, protected status limits some of the code, and private allows only specified users see the code. The abstract class in PHP can be set as public or protected, but it cannot be private.

WiseGeek is dedicated to providing accurate and trustworthy information. We carefully select reputable sources and employ a rigorous fact-checking process to maintain the highest standards. To learn more about our commitment to accuracy, read our editorial process.

Discussion Comments

WiseGeek, in your inbox

Our latest articles, guides, and more, delivered daily.

WiseGeek, in your inbox

Our latest articles, guides, and more, delivered daily.