Object Oriented Programming Problem

Posted by Danny Love on Stack Overflow See other posts from Stack Overflow or by Danny Love
Published on 2011-06-24T07:32:45Z Indexed on 2011/06/24 8:22 UTC
Read the original article Hit count: 236

Filed under:
|

I'm designing a little CMS using PHP whilst putting OOP into practice. I've hit a problem though.

I have a page class, whos constructor accepts a UID and a slug. This is then used to set the properties (unless the page don't exist in which case it would fail). Anyway, I wanted to implement a function to create a page, and I thought ... what's the best way to do this without overloading the constructor. What would the correct way, or more conventional method, of doing this be?

My code is below:

<?php

class Page {

private $dbc;

private $title;
private $description;
private $image;
private $tags;
private $owner;
private $timestamp;
private $views;

public function __construct($uid, $slug) {

}

public function getTitle() {
    return $this->title;
}

public function getDescription() {
    if($this->description != NULL) {
        return $this->description;
    } else {
        return false;
    }
}

public function getImage() {
    if($this->image != NULL) {
        return $this->image;
    } else {
        return false;
    }
}

public function getTags() {
    if($this->tags != NULL) {
        return $this->tags;
    } else {
        return false;
    }
}

public function getOwner() {
    return $this->owner;
}

public function getTimestamp() {
    return $this->timestamp;
}

public function getViews() {
    return $this->views;
}

public function createPage() {
        // Stuck?
    }
}

© Stack Overflow or respective owner

Related posts about php

Related posts about oop