Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php instance class from string

$class = 'FooBarMyClass'; 
$instance = new $class();
Comment

php class instance

<?php
// Create the class first...
class Person
{
    public $name;
    public $surname;
    
    function __construct($name, $surname)
    {
    	$this->name = $name;
        $this->surname = $surname;
    }
    
    function getName()
    {
    	return $this->name;
    }
    
    function getSurname()
    {
    	return $this->surname;
    }
    
    function setName($value)
    {
    	$this->name = $value;
    }
    
    function setSurname($value)
    {
    	$this->surname = $value;
    }
}

// Now, you can create an instance of the class
$me = New Person("John", "Doe");
echo $me->getName();
$me.setName("Jane");
echo $me->getName();

/**
   I hope that this helps ^_^ 
 **/
?>
Comment

PREVIOUS NEXT
Code Example
Php :: Laravel Google Line Chart 
Php :: php link 
Php :: paginate array before more results php 
Php :: guzzle download file 
Php :: laravel collection shift 
Php :: laravel request protected prop 
Php :: laravel index method 
Php :: laravel log error 
Php :: php access multidimensional array by string 
Php :: using custom fonts in php 
Php :: php if null then 0 
Php :: php header author 
Php :: laravel show method 
Php :: twig render to variable 
Php :: php variable 
Php :: Laravel unique cheque using multiple column 
Php :: @yield extends laravel 
Php :: how to migrate new column without empty the table in laravel 
Php :: if ip is 
Php :: php typecast class 
Php :: laravel print builder 
Php :: php interview questions for 2 year experience 
Php :: laravel blade @if 3 varabile 
Php :: randhex php 
Php :: oop php 
Php :: compress video file size php 
Php :: php spreadsheet styles 
Php :: php Constant expression contains invalid operations 
Php :: laravel login and registration with command 
Php :: php interview questions for experience 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =