Access modifiers in PHP. Code example open

Access modifiers in PHP. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators

With access modifiers you can set the scope of properties (variables) and properties (functions) of the class.
There are the following modifiers:

public – properties and methods can be accessed from external code and from any part of the program.

protected – properties and methods are available from the current class, as well as from descendant classes.

private – properties and methods are available only from the current class.

!If a method or property does not have an access modifier, then by default its visibility is similar to the public modifier.

<?php
class Person
{
    private $private ="private";
    public $public = "public";
    protected $protected = "protected";
}
?>

All properties and methods with modifiers public and protected are available to the derived class, but methods and properties with
private modifier.

In PHP, in a class, you can access variables and methods with the private and protected modifiers of an object of the same class.

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation