Php - Class

> Procedural Languages > Php

1 - About

A class is the blueprint code that create an object.

3 - Example

<?php
class Foo {
 
    // A variable
    public $myPublicVar = 'value';
    private $myPrivateVar = 'value';
 
    // A constant   
    const CONSTANT = 'constant value';
 
    function showVariable() {
        print 'Print a variable '.$this->myPublicVar;
    }
 
    function showConstant() {
        echo  self::CONSTANT . "\n";
    }
 
    public static function aStaticMethod() {
        // ...
    }
} 

4 - Documentation / Reference

Advertising