Questions tagged [php]
Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.
2,059 questions
2 votes
2 answers
148 views
How to namespace global function overrides?
In PHP, trim() exists. By default the second parameter is " \n\r\t\v\x00" I wish to introduce my own version which doesn't deviate far from the core functionality: // Trim whitespace in ...
3 votes
1 answer
194 views
How should User behaviour depending on role be design as OOP
Imagine I got user which might be either author, administrator, reviewer An author have relation on book that he wrote. An administrator have relation on banned user (we track which administrator ...
2 votes
1 answer
200 views
Is widening parameter types in a PHP interface implementation a good practice?
I have an interface defined as follows: interface MyInterface { public function setMyMethod(int $a); public function getMyMethod(): int; } And I have a class that widens the parameter type: ...
0 votes
1 answer
389 views
How to share transaction across multiple repositories in DDD?
We are trying the Domain Driven Development (DDD) while working on a project. We've got a Product aggregate. We've got a ProductRepository to load/save Products. We've also got a Timeline aggregate, ...
4 votes
2 answers
308 views
Interface + Trait vs Abstract Class
While developing my application I faced an interesting situation: I have multiple DTO's which are almost identical in terms of methods, only properties are different. For example I have AccountDTO ...
-3 votes
1 answer
145 views
Mock an API for development purpose (no testing)
If I want to implement a connection from my software to an API, which is documented but not accessible yet, what is a common way to imitate the API until it is available? My first idea was to mock the ...
2 votes
1 answer
192 views
How is $this provided in PHP?
I got a fundamental question about the $this keyword in PHP and how it is defined. Pracitcally, I know what it is and what it does. But I am interested in how it is provided / implemented? For example,...
-1 votes
1 answer
249 views
Best practices for organising PHP files?
I am currently writing a PHP / JavaScript application library, which I intend to use in the future for several other applications. The library includes functionality for handling a database, creating ...