2

I've got for example a watermark file: ROOT.'/media/watermarks/1.jpg'.

In the future user can use (in some custom php template system) for example: 'watermark-filename', 'watermark-basename', , 'watermark-directory', etc to get needed data.

I'm trying to create some reasonable global variables names.


The question is, what does really 'basename' mean?

Terminal:

basename /path/to/source/file.ext -> "file"

PHP:

<?php
    echo basename('/path/to/source/file.ext'); // file.ext

    $path_parts = pathinfo('/path/to/source/file.ext');
    echo $path_parts['basename']; // file.ext
?>

Wikipedia:

Many file systems, including FAT, NTFS, and VMS systems, allow a filename extension that consists of one or more characters following the last period in the filename, dividing the filename into two parts: a basename or stem and an extension or suffix used by some applications to indicate the file type.

I know Wikipedia is not a source, but according to my best knowledge, in operating systems

filename = file.ext
basename = file
extension = ext

While in php:

filename = file
basename = file.ext
extension = ext

Why?

halfer
  • 19,824
  • 17
  • 99
  • 186
Jacek Kowalewski
  • 2,761
  • 2
  • 23
  • 36
  • So, the denomination is arbitrary. How is your question related to variable names now? – mario Jan 14 '15 at 07:04
  • Thanks for comment. I'm trying to make a consistent naming on my whole system, and I cannot decide which one to use. I thought it is arbitrary, but is there any reason why php use such a strange naming? PHP is based on C, where basename is also "normal". Was someone drunk while writing it? :) – Jacek Kowalewski Jan 14 '15 at 07:13
  • Unix filesystems don't actually have a concept of filename extensions. They're just used decoratively, or interpreted at the application level. (Apache for example interprets multiple "extensions" even). The POSIX `basename` function also just splits dirname from paths; as does the `basename` command line tool, which PHPs `basename()` function is modeled after. – mario Jan 14 '15 at 07:20
  • OK. I think this is worth the answer, as all my doubts are dispelled now. Please, post an answer with possible sources, and I will accept it :). Thanks for Your time and help. – Jacek Kowalewski Jan 14 '15 at 07:23

0 Answers0