Comment by bdsl on How can I handle a leap second correctly in my application
> Timestamps are just number of seconds (all seconds, doesn't matter leap or not) that pass from predefined date This isn't true. The unix timestamp explicitly excludes leap seconds. It counts only...
View ArticleComment by bdsl on PHP Unit Testing without a framework... Possible? Advisable?
@Gordon PHPUnit is itself a framework
View ArticleComment by bdsl on Theory: Compression algorithm that makes some files...
This doesn't seem remarkable - plain ascii files use only 7 bits out of every 8, so there's quite a bit of space (every 8th bit) for the file to 'grow' into without actually growing on disk.
View ArticleComment by bdsl on PHP: Best way to get a DateTimeImmutable object for a...
They're badly named, at least by current fashions. They should be wither methods instead of setter methods.
View ArticleComment by bdsl on Why is my stencil components library failing to generate a...
@AndrewF Sorry, I haven't found an answer yet.
View ArticleComment by bdsl on Is there an elegant way to have value objects in typescript?
And I see that this works even if I create another class LegalName with the same shape but a different validation rule - e.g. perhaps a LegalName has to contain a space. If I try to use one in place of...
View ArticleComment by bdsl on Why are TypeScript arrays covariant?
PHP has a built in array type that's different to anything else in the language, and they are not generally aliased. Instead a copy-on-write system is used when assigning or passing. I think it avoids...
View ArticleAnswer by bdsl for Passing popup link so it shows on the address bar
You can use the Javascript history API to change the address in the address bar without reloading the page. Mozilla provides instructions at https://developer.mozilla.org/en-US/docs/Web/API/History_API
View ArticleHow safe is it to use PhpStorm's refactoring commands
I have some PHP code that is does not have good test coverage and is not easily testable in its current state. If I use commands from the refactor menu of PhpStorm, and make no other changes, how sure...
View ArticleAnswer by bdsl for Should I use GET or POST when requesting sensitive data?
If the data is highly sensitive, consider using a POST. It's easy to issue a GET request without much thought - for instance if someone is looking at log file while logged in to the application with...
View ArticleAnswer by bdsl for How to handle config files and default settings when using...
Don't have a configuration file. Let the code which includes your project set configuration values at run time.If you are working in object oriented php you may want to take any required configuration...
View ArticleAnswer by bdsl for PHPUnit Mock Change the expectations later
Continue building the mock in setUp() but set the expectation separately in each test:class FooTest extends PHPUnit_Framework_TestCase { private $myservice; private $foo; public function setUp(){...
View ArticleAnswer by bdsl for Send email with a template using php
Create your template file, e.g,/path/to/templates/template.twig:Dear {{name}},Thank you for writing to us about {{subject}}.Then follow the instructions at https://twig.symfony.com/doc/2.x/api.html to...
View ArticleAnswer 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