Posts tagged with language

Compile time generics: yay or nay?

thephp.foundation

One of the most sought-after features for PHP is Generics: The ability to have a type that takes another type as a parameter. It's a feature found in most compiled languages by now, but implementing generics in an interpreted language like PHP, where all the type checking would have to be done at runtime, has always proven Really Really Hard(tm), Really Really Slow(tm), or both.

Read more [thephp.foundation]

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

A Look At PHP’s isset()

medium.com

Liam Hammet wrote a good blogpost on the isset language construct.

Let’s take a look through how isset behaves and what’s so special about it. Even if you’re a veteran PHP developer, hopefully, you’ll pick up something new here.

Read more [medium.com]

Notes on PHP RFCs, and topics that occur repeatedly on PHP internals

github.com

Dan Ackroyd maintains this interesting repo on GitHub with thoughts on why some PHP RFC's are not implemented yet. High on on my wishlist: Briefer closure syntax and Generics

There are some notes on PHP RFCs, why some were declined, and what others might need for them to be implemented. The purpose of these documents is to avoid information from being lost and to try to avoid conversations needing to be repeated multiple times on PHP internals.

Read more [github.com]

Community-driven PHP 8 Wish List

blog.nikolaposa.in.rs

Nikola Poša did some light research on what features PHP developers are craving for to be added in PHP 8. Seems like I'm not the only one that wants arrow functions and generics.

It's been over two months since I started a research on Twitter about the things that developers would like to be added or improved in the next major PHP release. It had a surprisingly long reach, inspiring developers, prominent experts, community representatives to express their opinion through more than a hundred responses.

Read more [blog.nikolaposa.in.rs]

What PHP can be

My colleague Brent shares some interesting thoughts on which direction PHP could go forward.

Let's take, for example, the debate about strong types in PHP. A lot of people, including myself, would like a better type system. Strong types in PHP would definitely have an impact on my daily work. Not just strong types, I also want generics, better variance and variable types. Improvements to PHP's type system in general would have quite the impact on my programming life. So what's stopping us from reaching a solution?

https://www.stitcher.io/blog/what-php-can-be

Read more

Language features and code properties

Josh Justice gives some solid advice on how to pick the right language for your next projects.

So to ask the question “should I use an OO or FP language (or style)” is to skip several steps. I think a better series of questions are: First, what properties would be beneficial for your application to have: concurrency? Immutability? Encapsulation? There are a lot of things you won’t know about your application at first, but you can at least know if it will be a backend app, JavaScript browser app, or native mobile app; if it will be CPU-bound or IO-bound; and if it will process data inputted by humans or automatically generated by machines. All of those factors can influence which properties you need.

Once that’s decided, the next question is, in a given language, are those properties guaranteed, easy, difficult, or not realistically achievable?

http://codingitwrong.com/2017/07/27/language-features-and-code-properties.html

Read more

Add syntactic sugar by preprocessing PHP

In an awesome article at Sitepoint Christopher Pitt explains how he used the yay macro library to build up plugin framework to add new language features to PHP.

Chris made plugins that allows this syntax in PHP.

// short closure syntax
$items = ["one", "two", "three"];
$ignore = "two";

array_filter($items, ($item) => {
    return $item !== $ignore;
});

//class accessors

class Sprocket
{
    private $type {
        get {
            return $this->type;
        }

        set {
            $this->type = $value;
        }

        unset {
            $this->type = "type has been unset";
        }
    }
}

As with all things, this can be abused. Macros are no exception. This code is definitely not production-ready, though it is conceptually cool.

Please don’t be that person who comments about how bad you think the use of this code would be. I’m not actually recommending you use this code, in this form.

Having said that, perhaps you think it’s a cool idea. Can you think of other language features you’d like PHP to get? Maybe you can use the class accessors repository as an example to get you started. Maybe you want to use the plugin repository to automate things, to the point where you can see if your idea has any teeth.

https://www.sitepoint.com/how-to-make-modern-php-more-modern-with-preprocessing/

Check out some more examples on preprocess.io

Very cool stuff.

Read more

The future of PHP

Anthony Ferrara gave a excellent "state of php"-talk at php[world].

PHP is experiencing a renaissance; old methodologies are everywhere under assault from advances in tooling and design. From Composer to HackLang, "the PHP way" of solving problems is dramatically evolving. Walls between projects are falling; interoperability and collaboration are happening on levels never thought possible. What do these accelerating changes mean for the future of the language? What might PHP8 look like? How will our communities continue to collaborate and evolve? And most pressing: what steps can we take to ensure PHP's continuing vibrancy in the face of future technical challenges?
https://www.youtube.com/watch?v=MWTe-iswnqc

Read more