Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

static functions php

class Products {

	protected $id;
    
    public function setId($id)
    { 
    	return $this->id = $id;
    }
    
    public function getProduct()
    { 
    	$arr_list = [
        				[
                          'name'=>'Proton',
                          'year' => 1987
                        ],
                        [
                          'name'=>'Produa',
                          'year' => 1990
                        ],
                    ];
    	return $arr_list;
    }

	public static function product_list()
    {
    	//whatever data want to return
        $arr_list = [
        				[
                          'name'=>'Proton',
                          'year' => 1987
                        ],
                        [
                          'name'=>'Produa',
                          'year' => 1990
                        ],
                    ];
    	return $arr_list;
    }
    
    
}

//static can call directly  
$lists = Product::product_list();

//non static
$product = new Product();
$lists = $product->getProduct();

//when calling class must alert memory consume. 
Source by www.php.net #
 
PREVIOUS NEXT
Tagged: #static #functions #php
ADD COMMENT
Topic
Name
7+4 =