Using Java-Style Namespace Convention in PHP or is it better to use X? [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I know that Namespaces in PHP are relatively new and so there are many possibilities to use them. Because it was not usable on the Server i did define my classnames like folder_folder_classname if they where in /folder/folder/classname.php
Now i want to change that to get better class names. I thought to redesign my class structure to a java based one, like com\domain\project\folder\folder\class (e.g. in java: com.domain.project.folder.folder package structure) and was thinking that this is a nice solution to avoid any problems with other classes i ever use and don't think about include() for my classes any more :)
So now my Questions:
Is this a good idea or should I use a better system for my php classes?
Is there a common handling for that in php?
(I saw that Zend Framework uses e.g. instead of Zend_Controller_Request_Abstract the namespace Zend\Controller\Request with class name RequestAbstract -> no domain and double wording...)
thanks for your answers :)

I would definitely avoid using the domain wording and just prepend the project name itself like Zend does (that way you avoid collision, too). Since you are thinking about restructuring and if you are using PHP > 5.3.0 (which you should) you might also want to consider the PHP namespaces.

Related

Laravel 5: constants.php vs constants in controller vs constants in model [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I'm using Laravel 5 and I need to add some immutable values (constants) to be able to make use of them in controllers mostly (maybe in views too). Question is: What's the best approach?
I've been reading and 90% of approaches suggest to use a constants.php and Config.get(), but I don't like this because (I think) a constant is not a config value. I mean, it's not supposed to be changed. In other frameworks, I like to use models or other lib class to define values related to the entity I'm working on, Eg.: I need a constant for cache time in users, then User::CACHE_1_DAY = '86400' (silly example btw).
I would recommend adding a new class containing Helper methods, and bind that class to the application in your AppServiceProvider.
Finally inside that class, place getter methods for the constants.

Emulating multiple and dynamic inheritance without PHP Traits below 5.4? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Background : in PHP 5.4 there are now traits which allow you to composite classes in a way that you can re-use those 'mixins' anywhere else too. That is being widely used in horizontal programming and comes with important benefits : reducing code bloat.
Question :
how to emulate the very same behavior on lower PHP versions by not going over the decorator pattern and static code generators ?
Requirements: the solution should work as you would expect from a language with proper multiple inheritance; also member-variable override in the order you've defined in the list of base-classes.
Solution(s) I have found so far :
The only real candidate at hand I've found so far is the 'class-mixer' over here. The problem with this script is that it partly depends on eval which may has some disadvantages. There are also a few other libraries but non of them really turned well, ie : constructor inheritance
Not really but acceptable results: Code-Generators as in Doctrine and others.
the last solution which came up was to emulate 'multiple inheritance', using the same approaches as in Javascript libraries, ie: implementing the C3 based algorithms.
thanks!

How to Parse a code file? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Writing from phone so sorry if not typed well. I want to Parse a file in php but it's a php file. I want to extract thinks such as namespace functions and classes. How is that best done?
I am reading in the php file like a text file and trying to understand where things start and finish.
I tried doing this all at the same time but because too confusing to apply parse.
So now I have different objects parsing. Namespace, classes, method.
But it's have to keep track what is where and what is inside what.
Keep in mind the different ways a namespace can be written in php. How would one do this. Parse the file and understand the classes and methods that are in it. This is not limited to php it will need to extend to other languages too.
PHP-Parser is a php parser written in php. I think this tool will fill your needs.
Have a look at the tokenizer extension. It basically offers you one function token_get_all() with the source code as a string (file_get_contents() first), and returns an array with all the code parsed into PHP internal atoms, which is way easier to parse than fiddling with the source yourself.

Has anyone here tried PHP On Pie? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I created this framework to fill what I felt was a need for a PHP-like framework that was really efficient. My goal is to make it into a real open-source project, but since I have never launched a popular open-source project, I could use some feedback and advice.
My question is, has anyone here used it, and if so, what was your experience?
Whether you have or haven't, do you have any advice for the non-programming aspects? What is it missing, in terms of
Documentation
Out of the box ease of use
Community features and support
Whatever else I can't think of right now.
Basically any advice on how I can take it from its current state and make it at least somewhat popular?
http://phponpie.com
I saw this before, but I wasn't sure at all why I should use this instead of Zend Framework or Symfony, so as zerkms said, it seems like just another framework.
The code quality has some question marks about it as well. The code seems to mix and match PHP4 and PHP5 styles (no visibility declaration on some class methods, some class constructors used PHP4-style constructors...) and it had inconsistent file naming (interface iDb in Db.php) and inconsistent coding style, even in the same file.
Not sure how easy it would be to unit tests apps written with this either.

Set apart functions [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What is good way:
Keep all functions in one file or to set apart them? (like database.php, session.php)
My approach is split functionalities into classes; and then to put each class into one file.
If you have a lot of functions, I would do the same - split them into thematically separate files and include them only when needed.
If you work with classes, you can make use of PHP's autoloader functionality that will automatically load any PHP files needed to instantiate a certain class.
I prefer using several distinct files -- generally, one per "group of features".
Advantages :
smaller files : easier to deal with in your IDE
several files : one developper can work on one feature, in one file, the other developper on another feature, in another file ; limits the risks of conflicts (yes, even with SVN and equivalents)
you only need to include what's needed
(And if you extend your question to classes : one class per file, structured in directories ; and using autoloading to include the files that are necessary)

Categories