Simon HolywellPHP and immutability: objects and generalisation - part three (27.4.2017, 03:01 UTC)

In the last article we learnt how to create modified copies of an immutable in PHP. This one is going to tackle an issue I have hitherto skirted around and avoided. Objects in immutable data structures.

This article is part of a series I have written on the topic of immutability in PHP code:

  1. Part two - improve the process of creating modified copies of the immutable
  2. Part three - objects in immutable data structures and a generalised immutable implementation

What’s the problem with objects?

Objects or instances of classes are passed by reference in PHP. Any changes to the class will be reflected in all places it is passed to. This is different to scalar values like strings, that are passed by value instead.

$class = new stdClass();
function addItem($x, $item) {
    $x->$item = $item;
var_dump($class); // object(stdClass)#1 (0) {}
addItem($class, 'test');
object(stdClass)#1 (1) {
  ["test"]=> string(4) "test"

Here you can see a function called addItem() that adds a property to stdClass instance - this produces a side effect. The original $class is also updated as it references the same value so if we dump the variable we can see it’s value has changed.

Now consider the same example with a simple scalar string where pass by value takes effect.

$string = 'begin';
function addItem($x, $item) {
    $x .= $item;
var_dump($string); // string(5) "begin"
addItem($string, 'end');
var_dump($string); // string(5) "begin"

Here the original value remains intact because, unlike an object, there is no reference to it from within the addItem() function.

These side effects make putting an object into an immutable data structure difficult. Someone with access to the reference could simply change the object after the fact - thus breaking immutability.

What about resources?

Turns out the same issues plague resources as well. They are just references to a resource ID so any change to one will affect all those that also reference it. Simply moving the pointer in a file resource would break immutability.

Truncated by Planet PHP, read more at the original (another 75420 bytes)

Nomad PHPAtlas: A Data Mapper For Your Persistence Model (26.4.2017, 10:00 UTC)

Speaker: Paul M. Jones @pmjones Atlas lets you build an OO model of your SQL tables and relationships. You can use it at the start of your project for basic CRUD operations. As you begin to need simple behaviors in your application, you can add them to the Record and RecordSet persistence model objects. Finally, …

The post Atlas: A Data Mapper For Your Persistence Model appeared first on Nomad PHP.

Paul M. Jones“A False Sense of Simplicity” (25.4.2017, 13:51 UTC)

These year-old posts from Piotr Solnica are about Ruby On Rails …

… but the experiences related therein should be valuable to anyone using or building a full-stack PHP framework. (I can imagine it applying to CMSes as well.)

Does this story from Piotr remind you of any framework-based project you’ve worked on in PHP?

Once, I joined an existing project. It was a huuuuge app which was running an on-line shopping community website. Complicated sales model, complicated promotions, complicated product setups, coupons, user groups, messages – it had it all. I joined them to help ship a few new features. One of my early tasks was to … add a link to something on some page. It took me few days to add this stupid link. Why? The app was a big ball of complex domain logic scattered across multiple layers with view templates so complicated, it wasn’t even simple to find the right template where the link was supposed to be added. Since I needed some data in order to create that link, it wasn’t obvious how I should get it. There was a lack of internal application APIs and relying on ActiveRecord exclusively made it extremely difficult.

I’ve consulted on projects like that more than once. Indeed, the posts might well have been subtitled “The Perils of Convenience-Oriented Development”:

People are attracted by Rails because it gives you a false sense of simplicity, whereas what really happens is that complexity is being hidden by convenient interfaces.

Read both of the posts, and see if you can relate. They just reinforce to me that this is what to expect when you embed your domain logic in your user interface logic.

Remember: with server-side web-based applications, the user interface is the HTTP request and response. Any code that reads from the request, or that writes to the response, is part of the user interface. Putting your domain logic in the user interface is convenient to start with, but as soon as things become even a little bit complex, that “convenience” becomes a burden.

PHP ClassesPHP 7.2 Release Date and Managers Being Chosen - 7 Minutes Lately in PHP podcast episode 82 (25.4.2017, 11:40 UTC)
By Manuel Lemos
PHP 7.2 development is reaching to the alpha stage in June, hopefully to have a final version released later this year. So for now the release managers are being chosen, so they can start preparing to work on each alpha, beta and release candidate version.

This was one of the main topics discussed by Manuel Lemos and Arturs Sosins on the episode 82 of the Lately in PHP podcast.

In this episode they also talked about other proposals for PHP cache keys for stream wrappers, serialized object validation with is_string, type variants, let range() return a generator, named parameters again, and removing the need for ; on the end of the line .

They also commented on an article about promoting Open Source projects using data mining and business intelligence to boost SEO factors, and using OpenID Connect protocol to implement single sign-on social login systems.

This article also contains a podcast summary as a text transcript and a 5 minute video of the summary.

Listen to the podcast, or watch the hangout video, or read the transcript text to learn more about these interesting PHP topics.
Voices of the ElePHPantInterview with Adam Englander (25.4.2017, 09:00 UTC) Link
Nomad PHPWhat I Learned About Testing WhileWalking Uphill Both Ways In The Snow (25.4.2017, 00:33 UTC)

July US Presented by Chris Hartjes (@grmpyprogrammer) Date: July 20, 2017 Time: 20:00 CDT 18:00 PDT, 3:00 CEST (July 21), 2:00 BST (July 21) Not sure of the time in your area? Check it on Back when I was learning about how to test PHP code, I had to walk both ways uphill in …

The post What I Learned About Testing While
Walking Uphill Both Ways In The Snow
appeared first on Nomad PHP.

SitePoint PHPHow Privileged Are Programmers? Are You a John, Too? (24.4.2017, 17:00 UTC)

John was a developer. To be specific, he was a young, white, straight, young, self-taught developer. He wasn't rare, but he was special. John grew up with a couple parents, who paid for everything he needed. John regularly filled his belly, with the finest food his family could provide. John got every toy he asked for, once he learn that asking for 3 toys was a good way to get at least 1 toy.

A spoiled child with many toys

John got average grades, but it was ok because [according to mum]; "he's just bored of schooling, and too clever". He walked right out of high-school and into a programming job. The pay wasn't great; only enough for a small apartment and modest groceries [for one]. In time he'd earn more.

Over the years, John quickly got bored of programming. He loved the thought of the career, but it was all so boring. He moved jobs every year or so, and only then when his idiot bosses stopped seeing how much he mattered to their company.

Person leaving a job happily

It was just as well, because most of the other developers he worked with were idiots too. Did they even know how to program? All they wanted to do was talk and ask questions and they weren't as interested in John's work as intelligent people should be. He did once work with a girl developer, though. She was so pretty for a programmer. I mean, if you can call CSS and HTML programming.

Illustration of a female web designer

I am angry.

For the longest time, I was John. I thought every boring task beneath me, every other developer mediocre at best. I was my own hero, and my mom was right (albeit annoying) that I was brilliant. If only those around me could see this.

Continue reading %How Privileged Are Programmers? Are You a John, Too?%

SitePoint PHPMake Your Own Social Network, Game Server, or Knowledgebase! – Sourcehunt (22.4.2017, 16:00 UTC)

It's time for our monthly hunt for new open source libraries to use and contribute to!

If you're new to Sourcehunt, it's our monthly post for promoting open source projects that seem interesting or promising and could use help in terms of Github stars or pull requests.

It's our way of giving back - promoting projects that we use (or could use) so that they gain enough exposure to attract a wider audience, a powerful community and, possibly, new contributors or sponsors.

Sourcehunt logo

Continue reading %Make Your Own Social Network, Game Server, or Knowledgebase! – Sourcehunt%

Nomad PHPAtlas ORM: Doing the Heavy LiftingFor Your Persistence Layer (22.4.2017, 15:43 UTC)

July 2017 EU
Presented By

Paul M. Jones
July 20, 2017
20:00 CEST

The post Atlas ORM: Doing the Heavy Lifting
For Your Persistence Layer
appeared first on Nomad PHP.

Evert PotI work at Yelp now! (21.4.2017, 18:26 UTC)


In a twisted turn of events, I suddenly find myself to be working for Yelp! It sounds a bit like it was a surprise, and it kind of was. Only 6 months after I started my job at Turnstyle, it got acquired by Yelp.

I would joke “I must have done something right”, but the truth is that I work with some extremely smart and genuine people, who totally earned this.

Working for a much larger company like Yelp will be a huge adventure, and a massive experience to learn from, so I feel really lucky to have jumped on this chance at just the right moment. I can’t wait to build great things with an army of smart people.

And who knows, maybe I’ll get to see a bit more of San Francisco in the future!

LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP