A
A
acspro2015-03-31 21:33:03
PHP
acspro, 2015-03-31 21:33:03

Is it possible to forbid creating an object in the constructor of this object (php)?

It's a stupid question, but still. Is it possible to forbid creating an object in the constructor of this object (php)? That is, how to ban? Whether in sense the object can destroy itself in the constructor.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alzasr, 2015-04-01
@acspro

It is generally impossible to forbid creating an instance of a class (if the class is not abstract), you can prohibit creating an instance from the outside by making the constructor private (private), but you can still create it in the class itself. Of course, you can throw an exception, but I did not check what will be the result of new.

S
Simasik, 2015-03-31
@Simasik

question. Why do this?

K
kompi, 2015-03-31
@kompi

Very similar to the singleton question .

H
he he, 2015-03-31
@tosha_lol_daaa

php.net/manual/en/closure.construct.php

O
olamedia., 2015-03-31
@w999d

what? prohibit creating an instance? private function __construct()
or inside __construct to prohibit creation of other objects? then no
or I don’t understand a damn thing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question