Jump to content

constant and class problem


ComGuar

Recommended Posts

Humm...

 

first, I would probably move my constants to a file outside the class and include them in the script in order to keep all constants in one location.

 

You have a high-level of restriction set on the sample code.. final classes are the end of the line, and can't be overridden or extended. Maybe not the best choice, but it all depends on your implementation

 

The use of OOP is to create widely reusable code that is usable in various projects.. declaring a filepath inside a class is not well-advised.

 

 

i suggest :

 

class myClass{
  // properties
  protected $_directory;
  // construct (used to pass attributes to the class)
  public function __construct($directory){
     $this->_directory = $directory
  }
}

 

This way, the directory used by this class can be called at runtime using

 

// instantiate the object
$object = new myClass(MY_DIR_CONSTANT);

 

And then you can work on that. I'd recommend grabbing an OOP book if none of this makes any sense. Let me know if you have any problems

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.