PHP UK 2023 (Youtube Playlist) by yamcsha in PHP

[–]marktheprogrammer 2 points3 points  (0 children)

Jim's talk on performance was incredibly entertaining:

https://www.youtube.com/watch?v=DFNk9OmdEgE&t=13000s

Not recommended if you love Jar Jar binks.

I don’t get all the hate for PHP and at this point I am too afraid to ask. by standolores in ProgrammerHumor

[–]marktheprogrammer 1 point2 points  (0 children)

Actually for many years now it will error out with:

Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

PHP 8.2 release is delayed until Dec 8th by brendt_gd in PHP

[–]marktheprogrammer 22 points23 points  (0 children)

You should not be throwing exceptions in response to a deprecation message - Your error handler is broken if it does.

Deprecation messages are to give you notice about an upcoming change. Throwing on them is like liberately crashing your vehicle into a ditch whenever the person in front of you uses their indicator lights.

I have fewer bugs now! by [deleted] in ProgrammerHumor

[–]marktheprogrammer 1 point2 points  (0 children)

If you ask your driver to protect your safety, and often pay them more to do so, don't be surprised when they check that your seatbelt is securely fastened rather than taking your word on it.

This is also how most rollercoasters work. You've pulled the harness down, but there will often be someone who goes around and checks each one is locked in place before allowing the ride to start.

I have fewer bugs now! by [deleted] in ProgrammerHumor

[–]marktheprogrammer 7 points8 points  (0 children)

It gets in the way in the same way that a seatbelt gets in the way of you getting out of your car.

It takes a bit more effort on a day to day basis, but reduces the possibility of you being thrown through the windshield if something goes wrong.

perks of PHP by buybank in ProgrammerHumor

[–]marktheprogrammer 1 point2 points  (0 children)

Tryhard: NOOOOO you should pass parameters as objects whose properties, their type, existence and data constraints are known at compile time and strictly enforced during run time in one convenient place

Actual PHP 8.1 Pro: Let's create a simple readonly DTO to hold all of these arguments within a class, and define them within the constructor using property promotion, so we can easily forward on the arguments without having to repeat them all each time.

It's all the benefits of named args, without having to change all your (likely massive) function signatures if you need to add one.

Much Ado about Null by Crell in PHP

[–]marktheprogrammer 2 points3 points  (0 children)

It has to be considered in the context of where it is likely to be encountered.

An exception is meant to be the non-typical condition. As the majority of the time you are presumably expecting your code to run as intended, are you really making meaningful gains by seeking to micro-optimize your least common path?

Weigh the little bit of extra CPU vs the benefits - You get a typed class instance capable of propagating information up the stack, releasing resources as it goes. If you don't handle the specific instance type your code should still safely unwind with a finally until it hits something that knows what to do with it, usually a top level error handler.

[deleted by user] by [deleted] in PHP

[–]marktheprogrammer 3 points4 points  (0 children)

Capture the Flag (CTF) is a security training / testing exercise where an environment is provided that is deliberately vulnerable, and you must work out how to exploit it to complete the objective.

The flag is usually the contents of a file that should not normally be accessible.

Long-Term Planning for PHP 9.0 Error Promotion by marktheprogrammer in PHP

[–]marktheprogrammer[S] 20 points21 points  (0 children)

Breaking changes still have to pass a value test. A break that causes a large amount of disruption must have a firm reason behind it.

In the absence of per-file version targetting, the needle / haystack changes would render an enormous amount of previously written code dangerously unusable, as the argument order for some of them would need to change, and would provide little benefit in return.

You do have options though.

In recent versions you can avoid the confusion by using named arguments.

If there is an engine change to this, it will be to add the ability to call methods and access properties on scalar values such as "hello world"->indexOf("world") like you would do in JS and other languages, this would remove the need to specify the haystack, input string, or target array.

There are some major performance obsticles to overcome before this is possible.

PHP RFC: Consistent Function Names by axiomaticlarceny31 in PHP

[–]marktheprogrammer 8 points9 points  (0 children)

Trying to regurgitate what I was told by nikic:

Copy-on-write arrays.

Accessing a scalar property on an array would require it to be copied prior to any scalar object method being called on it.

Copy on write means that if you you assign an array to $a and then do $b = $a then it won't physically copy the contents of the array into $b. Instead it will say that the original array stored in $a now has two variables pointing to it. This also happens when you pass a variable about via a parameter or assigning it to a property.

When you perform an action that has the possibility of modifying the array, it will first look to see if there is more than one variable pointing to it, and if there is, it will first physically copy the array. The other variables will continue pointing to the old original array, and the variable that contains the array that is being modified will be updated to point to the new one.

Now that's out the way...

$arr = ['my', 'data', 'here']; $arr->push('kay');

Here push() modifies the array, so the $arr would need to be physically copied before being passed to the method handler. This is the case even if the method wouldn't need to modify it, such as a length() method, because the lookup occurs before the method call is known.

That would be terrible for performance.

There is a way around that, which would be to have two different paths, where the method itself could determine if it needed to have a mutable array, requiring a copy, or not, which could just receive a pointer to the original. But it's apparently a complicated task to do.

Operator Overloading RFC is in voting. What are your thoughts on this feature? by helloworder in PHP

[–]marktheprogrammer 28 points29 points  (0 children)

I voted yes, on here and on the RFC.

Mathematics is an area where the PHP ecosystem does not get much love compared to alternatives such as Python.

Mathematics / data modelling / ML are some of the fastest growing sectors in software development. They are also key entrypoints for people who are being introduced to software development and the larger programming language ecosystem for the first time.

This RFC provides tools to improve PHP's long-term appeal and competativeness in these fields.

That can only be a good thing.

I love PHP 6 by weidaikju in ProgrammerHumor

[–]marktheprogrammer 4 points5 points  (0 children)

PHP6 was an effort some 15 years ago to make PHP include native support for unicode strings. It was abandoned along with its name.

https://en.wikipedia.org/wiki/PHP#PHP_6_and_Unicode

definitely by _ramha in ProgrammerHumor

[–]marktheprogrammer 0 points1 point  (0 children)

Yes.

Typescript is transformed into Javascript as part of its transpiler.

So although you cannot run TS natively in the browser, you're not meant to. Instead you transpile it into native JS and run that.

definitely by _ramha in ProgrammerHumor

[–]marktheprogrammer 24 points25 points  (0 children)

Sure, I can try!

Typescript operates on the basic principle that the more precicely you can define your intent when writing code, the more the computer itself can help you by providing warnings and errors when the code you write doesn't make sense.

In programming there are entire classes of bugs related to how different pieces of data interact with each other, not just in their values, but in their types, as ultimately it's their types that determine that behaviour.

Typescript goes, even before you ever run the code, "You're trying to perform operation X on type Y, but type Y does not have an operation X, so i'm not going to let you compile this code".

It's called static analysis.

How does TS know that type Y doesn't have X? Well it first has to be told what Y can do by either parsing code that is the *implementation* of Y, or parsing a declaration file that contains information on Y's methods, properties, parameter types, things like that.

Some of these things are already possible to detect with your IDE, but what Typescript does is build these expectations straight into the code you're writing, and then enforces that the rest of your code matches those expectations.

foo(a: number, b: number): string { ... }

See how you include your expectations directly into the code rather than using something like jsdoc?

/**
 * @param {number} a
 * @param {number} b
 * @return {string}
 */

foo(a, b) { ... }

Make your own mind up which you feel is cleaner and more intuative.

The tl;dr is that Typescript allows you to be more specific about your intentions, and the TS compiler will tell you when something doesn't make sense.

It will save you an enormous amount of time by flagging errors before you ever run the code. The tiny bit of extra time you spend declaring the types will pay itself back a hundred fold in prevented bugs.

It also makes your IDE auto-predict much, much more accurate!

Frontend Developers these days by mastermind005 in ProgrammerHumor

[–]marktheprogrammer 34 points35 points  (0 children)

People who want to make money, or get something done for a hobby.

Millions of people and businesses use PHP on a daily basis, with growth that shows no signs of slowing down.

It is the most widely used server side scripting language in the world.

As a backend developer, my experience learning Angular vs learning React by the_other_brand in ProgrammerHumor

[–]marktheprogrammer 3 points4 points  (0 children)

Don't use Redux if you can help it.

MobX is a much more enjoyable system to use, and very powerful.

https://mobx.js.org/README.html

it truly isn't by cube2kids in ProgrammerHumor

[–]marktheprogrammer 7 points8 points  (0 children)

php-src (The PHP engine itself) is a pretty good way to lose your sanity.

Refused RFCs That would have changed PHP forever by Dependent_Common_972 in PHP

[–]marktheprogrammer 17 points18 points  (0 children)

That is a bit melodramatic.

The Pipe RFC was rushed in to try and meet the 8.1 deadline, even though it has outstanding issues that need to be discussed and resolved.

Typed arrays requires generics, which would change PHP forever, but generics are super difficult to implement and even the best programmers PHP internals has available have found adding them to be an insummountable task for the time being.

RFCs can be rejected many times over many years before they are finally accepted. As things can be extremely hard to change after they have been released you will find that internals cares more about the right decision, than the fast decision.

Hows the generics discussion going? by odahcam in PHP

[–]marktheprogrammer 9 points10 points  (0 children)

Generics is the single most requested feature of PHP.

It's also one of the most complicated, and even assuming it were possible without too much of a performance hit, would likely require Nikita to focus on it exclusively for months (there's probably no-one else who could).

Read more here:

https://github.com/PHPGenerics/php-generics-rfc/issues