Answer by bdsl for PHP Counter Using OOP
Use UpperCamelCase for class names. LogFile, not LOGFILE. When you have a variable and the most interesting thing about it is that it's expected to hold a reference to something that is_aLogFile you...
View ArticleAnswer by bdsl for What exactly mean by "PHP combined with MySQL are...
The point is that you may want to have more than one environment where PHP and Mysql are combined. At a minimum you probably want a Dev environment where you write the code and do initial tests, and a...
View ArticleUnit testing legacy php application — how to prevent unexpected database calls
I'm adding unit tests to a legacy PHP application that uses a MySQL compatible database. I want to write genuine unit tests that don't touch the database.How should I avoid accidentally using a...
View ArticleAnswer by bdsl for Domain (country) realted banners in PHP based system
your idea 1) will probably work for most cases, but sometimes users will get the wrong one depending how they connect to the internet, and gives you problems with things like search engines which you...
View ArticleAnswer by bdsl for PSR-1 2.3 Side Effects Rule example
Yes, you may use include inside a function.As far as this rule is concerned you can do anything you want as long as inside a function. Simply executing or including a file that declares a function...
View ArticleAnswer by bdsl for Get only list of ID's from ManyToMany with Doctrine
I don't believe it's possible to do what you with the entities defined the way they are. The Doctrine PersistentCollection class will always initialise itself, loading all the entities from the DB when...
View ArticleAnswer by bdsl for Can I really do nothing with fatal parse errors?
I don't think PHP can do anything with parse errors (or other errors during the compilation phase), but you should be able to configure your web server to display an error page of your choosing.You...
View ArticleAnswer by bdsl for Can a function be passed as a default parameter somehow?
No, you can't call a function to provide a default argument value. As the docs put it, "The default value must be a constant expression, not (for example) a variable, a class member or a function...
View ArticleAnswer by bdsl for Can parameter types be specialized in PHP
The code shown in the question is not going to compile in PHP. If it did class Bar would be failing to honour the gurantee made by it's parent Foo of being able to accept any instance of TypeA, and...
View ArticleHow to remove commits from parent branch when rebasing?
Suppose I have a branch widget, which was made by branching off feature and adding several commits about building the widget.I now want the widget to be available in master, without the rest of the...
View ArticleAnswer by bdsl for Can you override interface methods with different, but...
PHP 7.4, released November 2019 has improved type variance.The code from the question remains invalid:interface Item { // some methods here}interface SuperItem extends Item { // some extra methods...
View ArticleAnswer by bdsl for How to call a PHP function within a function when the main...
If you return a value from the myMenu function, you can assign it to a variable in the myPage function. Something like this:function myMenu() { return "menu";}function myPage() { $content = myMenu();...
View ArticleComment by bdsl on Is there any way to import Javascript value that was not...
@Barmar I don't think that helps me. It doesn't seem to get me any closer to be able to call someHelperMethod from inside something like a spec file that I'm going to run with the Jasmine test runner,...
View ArticleComment by bdsl on Is there any way to import Javascript value that was not...
Thanks, looks like this could work - either with a script to run the fs version before the test suite every time to make sure I'm testing the current code, or the eval version. Will have to see if it...
View ArticleComment by bdsl on Why are php array keys case sensitive?
Yes, converting to lowercase before hashing is much more sensible. But as I detailed in my answer that's not a trival task either if you can't control what encoding the text will be supplied in.
View ArticleAnswer by bdsl for Why are php array keys case sensitive?
PHP has no built-in encoding of text strings. While there are functions that support various encodings, especially UTF8 and related encodings, for the most fundamental parts of a language a string is...
View ArticleComment by bdsl on Is there an error baseline feature for Typescript
@weirdan Type checking and transpilation are separate in Typescript. The type information does not affect what happens at runtime, and if there are type errors (not syntax errors) then the TS compiler...
View ArticleComment by bdsl on Why is never assignable to every type?
A type can be thought of as a set of values, or terms, not a set of types. unknown can be thought of as a superset of all other types, not a set of all other types. number is a subset of of unknown,...
View Article