0

I'm currently doing a controller, and I want the controller to be null if the parameter pass to the controller does not match an entry in the database, so my question is the following, can I set the object instance to null from the object constructor?

Here's what I'm trying to achieve

public function __construct() {
    unset($this);
}

Is this possible?

3
  • is it possible? i dont know, have you tried? is it bad design? yeah, you would lose all methods and attributes and at that point, why bother using an object? Commented Mar 9, 2018 at 19:23
  • I don't fully understand your use case but it does sound like bad design... Why not have the class responsible for instantiating it not instantiate it depending on the database value? Commented Mar 9, 2018 at 19:26
  • 1
    You can't unset($this), not possible. All you need to check any property to validate if that contains anything, so why complicating things? Commented Mar 9, 2018 at 19:26

1 Answer 1

2

This is not really possible, consider that you would somehow have to clear all external references to the object from within the object itself which is not possible.

Additionally this is bad design because a controller object should be a mediator between a model and a view and should itself not be dependent on a model value.

It is a model object which represents a database entity and that would be null because it did not exist in the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.