6

I have struct:

/VBAL/
/VBAL/Interface/
/VBAL/Interface/Named.php
....
/VBAL/Component.php

Component.php:

namespace JV\VBAL; 
class Component implements \JV\VBAL\Interface\Named {}

Named.php:

namespace JV\VBAL\Interface;
interface Named {}

But I've got parse error:

Parse error: syntax error, unexpected '{', expecting T_STRING or T_NAMESPACE or T_NS_SEPARATOR

How do you call the directory "namespace", or place the files?

krzysiej
  • 889
  • 9
  • 22
ajile
  • 666
  • 1
  • 10
  • 18
  • Are you looking for a `Cascade File System` method? – yoda Aug 09 '11 at 10:04
  • I am looking for a way of placing files in php for the greatest transparency,understanding of the code,the directory interface is more appropriate for the interface files,but it seems so impossible to call the namespace so looking for another name,or a way of placing files, such as how you look at that option: move the file Named. php in the directory /VBAL/Component/ (create directory Component resp. for Component.php),but it deprives the flexibility to use this interface,because it becomes a priority attached to the class Component.Maybe there are ways to accommodate files that I do not know – ajile Aug 09 '11 at 10:12
  • check this, might give you some tips : http://kohanaframework.org/3.2/guide/media/kohana/cascading_filesystem.png – yoda Aug 09 '11 at 10:22

2 Answers2

17

Interface is a reserved word in PHP. You can't use it as part of your namespace.

Mchl
  • 61,444
  • 9
  • 118
  • 120
  • Yeap, I know, but how it resolve, for example, may be generally accepted standards of the name of the directory... – ajile Aug 09 '11 at 14:51
  • It's not PHP 5.3+ standard for sure. If you want your namespace to reflect your directory structure and vice versa, you can't have namespaces called `Interface`, `Class`, `Function` etc. BTW: You can't have a class called `Class` or `Interface` too. – Mchl Aug 09 '11 at 14:53
  • But Interfaces is plural and it's a problem if all folders in the tree are singular names (Model, Form, Exception, ...) – Julien Dec 16 '13 at 17:16
  • Indeed it is. Remember: there are only two hard things in computer science: http://martinfowler.com/bliki/TwoHardThings.html – Mchl Dec 17 '13 at 12:51
  • 1
    In my case it was Abstract – Nieminen Oct 20 '20 at 02:56
1

As mentioned before Interface is reserved word and can not be used as part of namepsace.

Two good alternatives are:

Base - in which you can store many base classes from which you extend, for example interfaces, abstract classes, traits

or Interfaces, but this one is in my opinion used little less because of it's plular form

LPodolski
  • 2,888
  • 4
  • 21
  • 24