Live data from Hacker News

PHP 8.1.0

php.net

281–286 of 286 posts

Re: PHP 8.1.0

#281
post #200

I sometimes wish I'd never learnt C#. I love property accessors, as I consider properties to be a part of public API and in PHP, there's no nice way around it other than the boilerplate getters and setters. Also I hope we'll get generics at some point. I know there are some issues with their implementation, but even non-runtime enforced generics would be better then relying on a docBlock annotation. Enums are neat, t…

You technically can use getters and setters in PHP, albeit with a noteworthy bit of extra implementation associated with wiring up __get() and __set().

Sure you can, the question is if you should. And you can't declare properties on interfaces (well, you can use @property annotation, but that's just... an annotation).

Re: PHP 8.1.0

#282

Earlier quoted context omitted.

There's already kinds of classes that can't be instantiated, why would this specifically be a breaking change?

If by "kinds" you mean abstract classes, yeah. I just checked, there's no special handling for those since requesting them from the container makes no sense. I suppose a constructor could depend on an abstract type and expect an actual implementation, though. I haven't thought about that use case actually, but it's possible to configure a substitute for this case. Other IoC containers may handle this one better, sinc…

[deleted]

Re: PHP 8.1.0

#284

Earlier quoted context omitted.

@Test public void testSomeMethod_FromStatic() { StaticWrapper1 staticWrapper = new StaticWrapper1(); int mockInput = 1; RegularClass rc = new RegularClass(); int expected = 2; int ret = staticWrapper.someStaticClass.someMethod(rc, mockInput); verify(staticWrapper.someStaticClass, times(1)).someMethod(rc, mockInput); assertEquals(expected, ret); } public class StaticWrapper1 { static class StaticClass { public int som…

Right, I mean, if you need to mock it a singleton would be a better choice; that's kind of the point of the pattern. Personally, though, I feel like if you frequently find yourself needing to mock these static classes, then they're not really as effective at avoiding statefulness as you claim -- if they're side effect-free, it should be safe to just use the implementation.

You need to mock them because you are asserting that it is the correct thing to use. Verification testing has nothing to do with state, per se. Having a static instance a wrapper just to use another static is java forcing unnecessary state. Forcing a singleton to instance another singleton at runtime is idiotic, which is why spring proponents avoid it and java is still a syntactical dinosaur. When we see proper modules (including static refs), java will be better fir it.

PHP is better with how it deals with statics today, which bleeds into other areas like testing.

Re: PHP 8.1.0

#285
Judging from the comments, it looks that many negations stem from the "old PHP". I've been developing with PHP since late 90s. Oh, boy, I've created a lot of bad code during all those years. However, when doing new year's retro, there has not been a single time I would be able to say that PHP has not evolved. As well as my code.

Modern PHP might not have all the shiny features other high profile languages have, but it's getting there. It's slower than many would like because of much debt and legacy. But it'll get there.

Also, you can write shitty code in any language. I would bet that, if back then python was as easy to deploy, as PHP, we'd now be fighting about that the same way as we are about PHP.

Re: PHP 8.1.0

#286
post #237

Earlier quoted context omitted.

From the top of my head, Javascript and Common Lisp will also work with "Hello World" (with quotes).

I can’t speak for Lisp, but JavaScript isn’t going to write that to standard out, it would just be a statement that didn’t do anything. You would need something like import { stdout } from 'process'; stdout.write("Hello World");

Fair enough. On the client (just opening dev tools) it would return the string, but as you say, it depends on what we count as valid (repl, server-side, client). Probably the closest would be

    console.log("Hello World")
Post reply on HN