Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this syntax supposed to do? [closed]

Tags:

oop

php

I am managing a website with a custom framework, developed by some programmers who are no longer working in out company. In some parts of the code I saw this:

$class = 'PagesControl';
$obj = clone new $class();

What is this thing supposed to do? Why would you clone an object created like that?

like image 888
Дамян Станчев Avatar asked Jul 02 '12 14:07

Дамян Станчев


People also ask

What is the syntax for closing a file?

Closing a file is performed using the fclose() function. fclose(fptr);

What is the standard syntax for close a function?

close(): This function helps to close an existing file. get(): This function helps to read a single character from the file. put(): This function helps to write a single character in the file.

Why is close function used?

The close() function shall deallocate the file descriptor indicated by fildes. To deallocate means to make the file descriptor available for return by subsequent calls to open() or other functions that allocate file descriptors.

How do you close a function?

Using return is the easiest way to exit a function. You can use return by itself or even return a value.


2 Answers

No, it is meaningless.

It should be:

$class = 'PagesControl';
$obj = new $class();

And if $class is fixed, then it should be $obj = new PagesControl();

like image 114
xdazz Avatar answered Oct 07 '22 02:10

xdazz


Maybe they have some strange setup in the __clone() method that need to be called just after instatiation but it would be pretty pointless. If the class PagesControl has no __clone() method, just take off the clone, otherwise put the code that is present in the __clone() method inside the __construct()

like image 42
Nicola Peluchetti Avatar answered Oct 07 '22 03:10

Nicola Peluchetti