Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
PHP Inheritance
Next article icon

PHP Inheritance

Last Updated : 24 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Inheritance in PHP is the ability of a class (known as a child class or subclass) to derive properties and methods from another class (known as a parent class or base class). Using inheritance, you can extend existing classes and modify or add new functionalities without changing the original code.

Syntax:

class ParentClass {
// Properties and methods
}
class ChildClass extends ParentClass {
// Additional or overridden properties and methods
}

Now, let us understand with the help of the example:

PHP

class Animal {
    public $name;
    public function eat() {
        echo "$this->name is eating.\n";
    }
}
class Dog extends Animal {
    public function bark() {
        echo "$this->name is barking.\n";
    }
}
$dog = new Dog();
$dog->name = "Buddy";
$dog->eat();   
$dog->bark(); 
?>

Output
Buddy is eating.
Buddy is barking.

In this example:

  • A class Animal is defined with a public property $name and a method eat(), which prints a message indicating the animal is eating.
  • A class Dog is defined that extends (inherits from) the Animal class. It adds a new method bark() that prints a message indicating the dog is barking.
  • An object $dog of class Dog is created. Since Dog extends Animal, it also has access to the eat() method inherited from the Animal class.
  • The $name property of the $dog object is set to the string "Buddy", which is the name of the dog.
  • The eat() method of the parent class Animal is called on $dog, and it outputs: "Buddy is eating."
  • The bark() method of the Dog class is called on $dog, and it outputs: "Buddy is barking."

Types of Inheritance in PHP

1. Single Inheritance

PHP supports single inheritance, meaning a class can inherit from only one parent class at a time.

PHP

class A {
    public function sayHello() {
        echo "Hello from A\n";
    }
}
class B extends A {
    public function sayHi() {
        echo "Hi from B\n";
    }
}
$objA = new A();
$objA->sayHello(); 
$objB = new B();
$objB->sayHello();  
$objB->sayHi();     
?>

Output
Hello from A
Hello from A
Hi from B

In this example:

  • Class A has a method sayHello(), which prints "Hello from A".
  • Class B extends class A, meaning it inherits the method sayHello(). It also defines its own method sayHi() which prints "Hi from B".
  • An object $objA of class A is created, and calling sayHello() prints "Hello from A".
  • An object $objB of class B is created, which can access sayHello() from class A and sayHi() from class B.
  • $objB demonstrates inheritance as it can use both the inherited method and its own method.
  • This is an example of single inheritance, where class B inherits from class A.

2. Multilevel Inheritance

In multilevel inheritance, a class inherits from a class, which in turn inherits from another class.

PHP

class A {
    public function greet() {
        echo "Hello from A\n";
    }
}
class B extends A {
    public function welcome() {
        echo "Welcome from B\n";
    }
}
class C extends B {
    public function message() {
        echo "Message from C\n";
    }
}

$objA = new A();
$objA->greet();  

$objB = new B();
$objB->greet(); 
$objB->welcome(); 

$objC = new C();
$objC->greet();   
$objC->welcome(); 
$objC->message(); 
?>

Output
Hello from A
Hello from A
Welcome from B
Hello from A
Welcome from B
Message from C

In this example:

  • Defines a method greet(), which prints "Hello from A".
  • Inherits from class A and adds a new method welcome(), which prints "Welcome from B".
  • Inherits from class B and adds another method message(), which prints "Message from C".
  • $objA can only access greet().
  • $objB can access greet() from class A and welcome() from class B.
  • $objC can access methods from both A and B and also its own message() method.
  • This is multilevel inheritance, where class C inherits from B, and B inherits from A.

3. Multiple Inheritance

PHP does not support multiple inheritance directly through classes, but you can use traits to simulate multiple inheritance.

PHP

trait Logger {
    public function log($msg) {
        echo "Log: $msg\n";
    }
}
trait Auth {
    public function authenticate() {
        echo "User authenticated\n";
    }
}
class User {
    use Logger, Auth;
}

$objUser = new User();
$objUser->log("This is a log message.");   
$objUser->authenticate();                  
?>

Output
Log: This is a log message.
User authenticated

In this example:

  • Defines a method log(), which prints "Log: [message]".
  • Defines a method authenticate(), which prints "User authenticated".
  • Uses both Logger and Auth traits, giving it access to both log() and authenticate() methods.
  • The object $objUser has access to both methods from the traits, simulating multiple inheritance.
  • This is simulated multiple inheritance in PHP using traits, where a class can inherit functionality from more than one source.

Note: PHP does not support multiple inheritance using classes. But you can achieve similar functionality using traits.

4. Hierarchical Inheritance

In PHP, hierarchical inheritance occurs when multiple child classes inherit from a single parent class.

PHP

class Employee {
  public $name;
  public $position;

  public function __construct($name, $position) {
    $this->name = $name;
    $this->position = $position;
  }

  public function introduce() {
    echo "I am {$this->name}, and I work as a {$this->position}.";
  }
}

class Manager extends Employee {
  public $team;

  public function __construct($name, $position, $team) {
    parent::__construct($name, $position);
    $this->team = $team;
  }

  public function introduce() {
    echo "I am {$this->name}, I work as a {$this->position}, and I manage the {$this->team} team.";
  }
}

class Developer extends Employee {
  public $programmingLanguage;

  public function __construct($name, $position, $programmingLanguage) {
    parent::__construct($name, $position);
    $this->programmingLanguage = $programmingLanguage;
  }

  public function introduce() {
    echo "I am {$this->name}, I work as a {$this->position}, and I specialize in {$this->programmingLanguage}.";
  }
}
$manager = new Manager("kriti", "Manager", "Sales");
$developer = new Developer("Ayushi", "Developer", "PHP");

$manager->introduce();  
$developer->introduce(); 
?>

Output
I am kriti, I work as a Manager, and I manage the Sales team.I am Ayushi, I work as a Developer, and I specialize in PHP.

In this example:

  • The Employee class defines properties like $name and $position, and a method introduce() that outputs the employee's details.
  • The Manager and Developer classes both extend the Employee class.
  • Both child classes call the parent constructor using parent::__construct() to initialize the common properties (name and position).
  • Each child class overrides the introduce() method to provide more specific information related to their roles (team for Manager, programming language for Developer).
  • Objects of the Manager and Developer classes are created, and the introduce() method is called for each, showing how hierarchical inheritance works.
  • This demonstrates hierarchical inheritance, where both the Manager and Developer classes inherit from the Employee class, but have different implementations of the introduce() method.

Constructor in Inheritance

If the parent class has a constructor, the child class must explicitly call it using parent::__construct().

class Person {
public function __construct($name) {
echo "Person: $name\n";
}
}
class Student extends Person {
public function __construct($name, $rollNo) {
parent::__construct($name);
echo "Student Roll No: $rollNo\n";
}
}

Overriding Inherited Methods in PHP

In PHP, you can override inherited methods by redefining them in the child class with the same name. This allows the child class to modify the behavior of the inherited methods while still retaining the structure of the parent class.


class Vehicle {
public $brand;
public $model;

// Parent class constructor
public function __construct($brand, $model) {
$this->brand = $brand;
$this->model = $model;
}

// Parent class method
public function description() {
echo "This is a vehicle of brand {$this->brand} and model {$this->model}.";
}
}
class Car extends Vehicle {
public $fuelType;
// Child class constructor
public function __construct($brand, $model, $fuelType) {
$this->brand = $brand;
$this->model = $model;
$this->fuelType = $fuelType;
}
// Overriding the description method in the child class
public function description() {
echo "This is a car of brand {$this->brand}, model {$this->model}, and it runs on {$this->fuelType} fuel.";
}
}
// Creating an object of the Car class
$car = new Car("Toyota", "Corolla", "Petrol");
$car->description(); // Output: This is a car of brand Toyota, model Corolla, and it runs on Petrol fuel.
?>

In this code:

  • The Vehicle class has two properties: $brand and $model, which are initialized using the constructor.
  • The description() method is defined to output a general description of the vehicle (brand and model).
  • The Car class extends Vehicle, meaning it inherits the properties and methods from the Vehicle class.
  • The constructor in Car overrides the parent constructor to also initialize the $fuelType property.
  • The description() method is overridden in the Car class to provide more specific details about the car, including the fuel type.
  • When you create an object of the Car class and call the description() method, the overridden method in Car is executed, outputting a more detailed description than the one in Vehicle.

The final Keyword

In PHP, the final keyword is used to prevent class inheritance or method overriding. When applied to a class or a method, it restricts further modification or extension.

1. Preventing Class Inheritance

You can prevent a class from being extended by marking the class as final. Any attempt to extend a final class will result in an error.


final class Cars {
// some code
}

// will result in error
class Honda extends Cars {
// some code
}
?>

In this example:

  • The Car class is marked as final, meaning no class can extend it (such as Honda).
  • Attempting to create a subclass (Honda) that extends Car will result in a fatal error because Car is a final class and cannot be inherited.

2. Preventing Method Overriding (Using final on a Method)

The final keyword can also be applied to methods to prevent them from being overridden by child classes.


class Animal {
// Marking the method as final to prevent overriding
final public function sound() {
echo "This animal makes a sound.";
}
}
class Dog extends Animal {
// This will result in an error, as sound() is final in the parent class
public function sound() {
echo "Bark!";
}
}
?>

In this example:

  • The sound() method in the Animal class is marked as final. This means that no child class (e.g., Dog) can override the sound() method.
  • If the Dog class tries to redefine the sound() method, a fatal error will occur because the method is final in the parent class.

Benefits of Inheritance

  • Code Reusability: Reduces code duplication by reusing existing code.
  • Scalability: Easier to scale and maintain applications.
  • Extensibility: Easily add new functionalities without modifying existing code.

Next Article
PHP Inheritance

P

pankaj_gupta_gfg
Improve
Article Tags :
  • PHP

Similar Reads

    PHP Introduction
    PHP stands for Hypertext Preprocessor. It is an open-source, widely used language for web development. Developers can create dynamic and interactive websites by embedding PHP code into HTML. PHP can handle data processing, session management, form handling, and database integration. The latest versi
    8 min read
    PHP | exit( ) Function
    The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The message
    2 min read
    Introduction to PHP8
    Back in the mid-1990s, PHP started as a Personal Home Page, but now it's known as Hypertext Preprocessor. It's a widely used scripting language that is perfect for web development and can easily be inserted into HTML. Over time, PHP has become super powerful for making dynamic and engaging web apps.
    5 min read
    PHP File Handling
    In PHP, File handling is the process of interacting with files on the server, such as reading files, writing to a file, creating new files, or deleting existing ones. File handling is essential for applications that require the storage and retrieval of data, such as logging systems, user-generated c
    4 min read
    Interesting Facts About PHP
    PHP is a widely-used open source and general purpose scripting language which is primarily made for web development. It can be merged into the HTML. Here are some interesting facts about PHP: The mascot of PHP is a big blue elephant.‘Personal Home Page’ is the original name of PHP.Today, PHP is reco
    2 min read
    PHP Array Functions
    Arrays are one of the fundamental data structures in PHP. They are widely used to store multiple values in a single variable and can store different types of data, such as strings, integers, and even other arrays. PHP offers a large set of built-in functions to perform various operations on arrays.
    7 min read
    PHP vs HTML
    What is PHP? PHP stands for Hypertext Preprocessor. PHP is a server-side, scripting language (a script-based program) and is used to develop Web applications. It can be embedded in HTML, and it's appropriate for the creation of dynamic web pages and database applications. It's viewed as a benevolent
    2 min read
    PHP file_get_contents() Function
    In this article, we will see how to read the entire file into a string using the file_get_contents() function, along with understanding their implementation through the example.The file_get_contents() function in PHP is an inbuilt function that is used to read a file into a string. The function uses
    3 min read
    PHP Date and Time
    PHP provides functions to work with dates and times, allowing developers to display the current date/time, manipulate and format dates, and perform operations like date comparisons, time zone adjustments, and more.In this article, we'll discuss PHP date and time.Why are Date and Time Important in PH
    5 min read
    Common Mistakes to Avoid in PHP
    PHP is a widely used server-side scripting language for web development. However, developers often overlook best practices, leading to vulnerabilities and inefficiencies. This article delves into common PHP mistakes and offers comprehensive solutions. Table of Content Not Using Prepared StatementsIg
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `${editorValue}`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { if(!loginData || !loginData.isLoggedIn) { grecaptcha.reset(); } jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('.suggest-bottom-btn').css("display","none"); $('#suggestion-section-textarea').hide() $('.thank-you-message').css('display', 'flex'); $('.suggestion-section').css('display', 'none'); jQuery('#suggestion-modal-alert').hide(); }, error:function(data) { if(!loginData || !loginData.isLoggedIn) { grecaptcha.reset(); } jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 4 Words and Maximum Words limit is 1000."); jQuery('#suggestion-modal-alert').show(); jQuery('.ContentEditable__root').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('.ContentEditable__root').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences