Hard coding the directory separator

require_once JPATH_COMPONENT.'/models/fields/courselist.php';


Soft code the directory separator


require_once JPATH_COMPONENT.DS.'models'.DS.'fields'.DS.'courselist.php';
  • Modern PHP versions works fine with "/" on both Windows and Linux.. so your method 1 would be sufficient..
    – Nagarjun
    Jun 3, 2015 at 7:57

2 Answers 2


I don't know if there's any difference in speed, but I find the first method easier to read. The reason to use DIRECTORY_SEPARATOR is to stay platform independent. Your second example:


would render like this on on Windows:


and like this on most other systems:


However, Windows is just as happy with a forward slash / as directory separator and will not complain.

  • thanks for your answer. When I use DIRECTORY_SEPARATOR for a javascirpt file then mozilla firefox (on my localhost) throws The requested URL was not found on this server. I believe it is better hard code the / instead of platform specific. Jun 2, 2015 at 21:14
  • Another reason to hard code the /. But maybe someone has a good reason to use DIRECTORY_SEPARATOR? Only reason I can think of is when exploding a path that the system gives you.
    – johanpw
    Jun 2, 2015 at 21:28

Joomla got rid of the DS constant with Joomla 3. It's no longer needed in most cases since PHP works fine with a forward slash even on Windows.

So don't use it.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.