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

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!

Related

How to handle a function with many dependencies [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 3 years ago.
Improve this question
I have a method that depends on many other classes like this
public function getProfileData(
ProfilesService $profile_service,
ContactInfoService $contact_info_service,
CoursesService $courses_service,
InterestsService $interests_service,
LanguagesService $languages_service,
PersonalInfoService $personal_info_service,
ProjectsService $projects_service,
SkillsService $skills_service,
AwardsService $awards_service,
EducationsService $education_service,
ExperiencesService $experiences_service,
TargetJobsService $target_jobs_service,
ProfileHiddenSectionsService $hidden_sections_service) { }
I read about dependency injection and I know that if you exceed 6-10 dependencies it leads you to a code smell.
But this getProfileData() method really need all of these dependencies so what is the best practice to solve this problem ?!
The code smell you are experiencing is called Constructor over-injection (and this particular variation is Method over-injection). As #Nkosi said in the comments, the source of this is a Single Responsibility Principle violation.
How to solve this problem, however, depends pretty much on the situation. Chapter 6 from the book Dependency Injection: Principles, Practices, and Patterns actually contains a very elaborate description of your options. In short, among other things, you can use the following refactorings:
Facade Services
Introduce Domain Events
Hide similar components behind a Composite
Extract cross-cutting concerns using Decorators

Is it possible to create a pure PHP Storm Topology? [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
According to the Getting Started with Storm book from O'Reilly:
There is a way to specify topologies in a non-JVM language. Since Storm topologies are just Thrift structures, and Nimbus is a Thrift daemon, you can create and submit topologies in any language you want. But this it out of the scope of this book.
I know the book is a little outdated, but I'm hoping this tidbit is possible.
Is there a way to submit a pure PHP Storm Topology?
From the documentation it says (as one of the key properties of storm)
Programming language agnostic: Robust and scalable realtime processing
shouldn't be limited to a single platform. Storm topologies and
processing components can be defined in any language, making Storm
accessible to nearly anyone.
You can probably look here for similar things.
Closest documentation of this that I've found:
https://github.com/nathanmarz/storm/wiki/Using-non-JVM-languages-with-Storm
It mentions where to get started. I guess I just have to do more research on this.

Using Java-Style Namespace Convention in PHP or is it better to use X? [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 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.

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.

Symfony VS CakePHP : which one is closest to PHP [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 9 years ago.
Improve this question
I'm mostly a Rails developer but sometimes, I have to code in PHP. Because stackoverflow.com prefers questions that can be answered, I'd like to have a idea which one of the two is closest to PHP?
Sometimes, I'm under the impression that CakePHP is a outdated copy of Rails that wants to look like Ruby but fails at it and thus leaving the best of PHP behind.
there are loads of questions dealing with the php framework issue.
for example:
php-framework-decision-analysis-paralysis
what-php-framework-would-you-choose-for-a-new-application-and-why
which-php-framework-is-closest-to-ruby-on-rails-cakephp-codeigniter
I don't think this question will bring anything new to light.
besides I think the framework of choice is more and more Zend Framework (IMHO).
How would you define closeness?
All frameworks are written in 100% PHP, non of them could be any closer to PHP. They are PHP.
I like symfony because it doesn't have PHP4 compatibility as a business goal. This lets the framework ditch some of the cruft and limitations of PHP4 and leverages the much stronger OOP in PHP5.

Categories