Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Calling itself a static function in php

//https://www.php.net/manual/en/language.oop5.static.php

self::staticMethod();
Comment

static function php

<?php
class Car
{
    public function test($var = 'Hello kinjal')
    {
        $this->var = $var;
        return $this->var;
    }
}
class Bike
{
    public static function test($var)
    {
        $var = '<br>this is static function';
        return $var;
    }
}
$obj = new Car();
echo $obj->test();
echo Bike::test('this is non static');      //static function called using :: double colon

?>
Comment

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. 
Comment

php call static method from class

ClassName::functionName();
Comment

php call static function from instance

$class = get_class($example);
$class::setData('some', 'data');
Comment

PREVIOUS NEXT
Code Example
Php :: php get multiple url parameters 
Php :: laravel collection combine 
Php :: yii 2 create migration with fields 
Php :: laravel relationship delete all 
Php :: codeigniter4 route optional parameter 
Php :: laravel generate unique string 
Php :: laravel datatable render html 
Php :: symfony form submit on refresh 
Php :: how to know if file is empty in php 
Php :: php file storage 
Php :: laravel basic login 
Php :: laravel merge two arrays helper 
Php :: laravel check if primary key exists 
Php :: Laravel 8 - get values of url query strings in controller 
Php :: laravel crud 
Php :: touches in laravel 
Php :: array_map in php 
Php :: show uploaded image in php 
Php :: how to check if a user is logged in in a non middleware controller in laravel 
Php :: mktime() php 
Php :: PHP stripcslashes — Un-quote string quoted with addcslashes() 
Php :: Regex to remove span tags using php [duplicate] 
Php :: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://D:/Program Files/Composer - PHP/composer.phar/src/Composer/DependencyResolver/Solver.php on line 223 
Php :: check if data inserted in database wordpress plugin 
Php :: Remove the Breadcrumb on the Shop Page 
Php :: audio validation in jquery validation 
Php :: php mysql update all rows in table random values 
Php :: guzzlehttp submit form file 
Php :: php ref parameter 
Php :: console_log in php 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =