I am carrying out a project in which I do not declare a constructor and, in this way, when creating an object, I only fill in the properties that I need at that moment. As an example:
class Publicacion{
private $id;
private $usuario;
private $fecha;
private $titulo;
private $contenido;
functions getters();
funtions setters();
function obtener_articulo(){
obtengo articulo a partir solo del id;
return resultado;}
}
In this case, if I only want to use the method, obtener_articulo()
I don't need to feed more than the property $id
:
$publi = new Publicacion;
$publi->set_id($el_id);
$articulo = $publi->obtener_articulo();
I feel it's very useful on a practical level but I wonder if it's a good practice or somehow it breaks OOP principles.