« first day (4018 days earlier)      last day (921 days later) » 

 
11 hours later…
12:01 PM
class A {
    function foo(string $bar) {}
}

class B extends A {
    function foo() {}
}
> Fatal error: Declaration of B::foo() must be compatible with A::foo(string $bar)
> As of PHP 7.4.0, full covariance and contravariance support was added.
dropping parameters isn't considered part of contravariance?
 
12:39 PM
@Danack there's a reason, but I don't know it, but yes, dropping parameters isn't part of contravariance
I haven't spent the time to read it carefully to where I'll understand clearly
 
function takesA(A $a) {
	$a->foo("whatever");
}

$b = new B();
takesA($b);
technically every function has all the parameters it needs....
 
cmb
but excess parameters are not "clean"
 
TS allows it, but it doesn't have runtime checking
 
12:55 PM
I maintain that a lack of purity in a language is a natural repellent to certain types of arseholes...
 
@Danack Rasmus is the antithesis of those types twitter.com/woketopus/status/1447150924846313475
 
1:18 PM
@Danack class C extends B { function foo(int $bar = 0) {} } would have to check all parents instead of only the current parent then for the compatibility check. It's compatible to B, but not to A.
 
 
2 hours later…
2:52 PM
Is this correct behaviour? 3v4l.org/QDT38
 
@Dharman I don't see the problem
 
cool
it caught me off-guard
 
cmb
no error on line 4; obviously runtime error only
or optimized away?
 
If the array has 0 or 1 element, the sort function is not called
 
I assume usort has an early return. It does not expect the function to cause side-effects
 
3:04 PM
As it is already sorted
Pretty sure that's also the case for non user based sort functions
as sorting is expensive
 
Unit testing is awesome BTW. I just caught !== vs === typo
 
 
3 hours later…
5:42 PM
Unit tests are great, but there are things that really need to be fixed in PHP src.
Do you know what my unit tests did not catch?
typos in property declarations
the whole code still worked and tests passed, but I had wrong property name
Dynamic property declarations must GO!
I don't care how. This thing is a menace
 
5:54 PM
you presumably aren't using PHPStan or Psalm then...yet.
@kelunik thanks....so borderline whether it should even be allowed, and would have a performance/complexity hit...
 
6:10 PM
@Dharman (In addition to static analysis) Why did your current tests not catch that bug? Consider whether you need more tests, or to revise your existing tests. Analyzing code coverage can help you spot code that's not covered by your tests.
 
6:22 PM
how can you test for that? As far as I know there is no way that unit tests can tell you that you mistyped property name. The code will still work fine
 
7:03 PM
Can't you extend classes from a base class that uses __get() and perhaps also __set() to catch those typos? (php.net/manual/en/language.oop5.overloading.php#object.get)
I've used that pattern myself for a few years now, and catched a few typos with it.
 
7:18 PM
That's not a bad idea.
 

« first day (4018 days earlier)      last day (921 days later) »