Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matt Sparks:
PHP Reflection
Jul 02, 2018 @ 17:42:41

Matt Sparks has posted a tutorial to his site introducing one of the more powerful but often misunderstood parts of the PHP language: its Reflection functionality.

Beginning work on the Analyze PHP framework, specifically the container, brought reflection to my awareness. Before that I had maybe heard the term, but I definitely hadn’t used it intentionally. Although it sounds like a scary computer science concept, it’s not. It’s actually quite simple:

Reflection is the ability of a computer program to examine, introspect, and modify its own structure… That’s it.

He starts the tutorial by introducing some of the basics concepts behind reflection in PHP and what it has to offer. He then shares some code examples of it in action getting class properties and getting the constructor. He also shows the use of other built-in PHP functions getting the class methods and the class name.

tagged: reflection tutorial introduction class method name properties constructor

Link: https://developmentmatt.com/php-reflection/

Tomas Votruba:
How to change PHP code with Abstract Syntax Tree
Feb 27, 2018 @ 18:11:13

Tomas Votruba has a post to his site that (sort of) continues his look at the parsing of PHP code into an AST and the use of the nikic/php-parser library. In this new post however, he covers several of the things that can be changed in PHP code using the library.

Today we can do amazing things with PHP. Thanks to AST and nikic/php-parser we can create very narrow artificial intelligence, which can work for us.

Let's create first its synapse!

He starts with a clarification about the difference between "php-ast" (an extension) and "PHP AST" (the actual abstract syntax tree). It then gets into some of the functionality that the php-parser library provides for modifying the PHP code being parsed. This includes changing method names, renaming properties, splitting classes and even potentially upgrading an application to a newer version. As an example he shows how to change the name of a method and write the result out to a file (all code is included).

tagged: phpast ast phpparser library change name tutorial

Link: https://www.tomasvotruba.cz/blog/2017/11/06/how-to-change-php-code-with-abstract-syntax-tree/

Freek Van der Herten:
Simplifying presenters in Laravel
Sep 20, 2016 @ 14:32:17

Freek Van der Herten has a quick post to his site with a tip about simplifying presenters in your Laravel based application. The "presenters" here are in relation to this package and how it helps with the output of the application.

In the Laravel template that we use to kickstart all our client projects at Spatie, I recently changed the way we handle presenters. Instead of using Jeffrey Way’s popular presenter package we now use simple traits. In this post I want to give some background on that change.

He gives a quick "crash course" on presenters for those not familiar with the concept and how it helps to keep view logic out of places like models and controllers. He briefly describes a presenter class that would return the "first name + last name" combination and what the code could look like. Then it's just a matter of using that trait (the class mentioned just before this) and a new magic property is defined to use in the view.

tagged: laravel presenter view logic property example user name

Link: https://murze.be/2016/09/simplifying-presenters-laravel/

Paul Jones:
When Possible, Use File *Resources* Instead Of File *Names*
May 13, 2016 @ 15:37:38

In this new post to his site Paul Jones makes a recommendation to those working with files and other resources: pass around the resources themselves (the streams) not filenames.

In testing the Aura.Http package, I have realized that it’s much more flexible, testing wise, to pass around file resources (a.k.a. handles, pointers, or streams) than it is to pass around file names. When you do that, you can use a php://memory stream instead of attempting to touch the file system. [...] This places control of the file creation in your hands directly, not under the control of the system under test.

He gives examples based on some testing of one of his own packages where he needed to swap out the resource being tested and mock out a file system call. It's a simple trick but could help reduce some complexity in your overall code in the right situations.

tagged: file resource name unittest testing aurahttp

Link: http://paul-m-jones.com/archives/2487

Joe Ferguson:
Install Homestead into your project
Jun 24, 2015 @ 14:53:42

As the Laravel News site mentions in one of their latest posts, the Laravel Homestead project received an update recently that makes it easier to install per-project rather than the previous "one install for everything" setup.

Over the weekend, Homestead received a new update that allows you to run it on a per project basis. Previously Homestead was designed so that you install it once on your system and share all your sites within the virtual machine. Joe Ferguson created the pull request to help get this feature implemented and he has a full write up on his blog.

This change pulls in the functionality doing all the hard work for you. It copies over needed files and setting up the Homestead vagrant instance directly from inside the project. Joe also describes the command line options you can provide, defining a name and hostname for the new instance. You can find out more about it in the official documentation.

tagged: laravel homestead project perproject command hostname name

Link: http://www.joeferguson.me/install-homestead-into-your-project/

Evert Pot's Blog:
Internationalized domain names, are you ready?
Oct 25, 2010 @ 14:44:13

In a new post to his blog Evert Pot looks at internationalized domain names and where they could cause issues some of the current validation in PHP applications.

Since may 11 TLD's (top-level domain names) have been added. In order for this to work successfully, a lot of applications will have to be fixed. Many email-validation scripts might use [a regular expression] approach [to match most address formats].

Unfortunately, this approach will only continue to work with the normal ASCII-based domain names. He includes a list of several that could break it including ones in Chinese, Korean, Persian, Russian and Arabic. He recommends a very liberal regular expression (one that allows for "punycode" strings) to check the email, find the record and try to find an MX record on that domain.

tagged: internationalized domain name validation email

Link:

Mark Karpeles' Blog:
proctitle: a new step for pinetd
Jan 22, 2009 @ 17:12:17

If you've ever worked with forking processes in PHP, you know things can get a little difficult when you have more than one process going at a time. Identification can become a hassle, especially if you need to kill one off because of performance issues. If you've found yourself in this spot before, you might want to check out this update Mark Karpeles has made to his pinetd project to allow for naming of those forked processes.

Ever wanted to give meaningful names to your processes when you pcntl_fork() with PHP ? proctitle is the extension you’re looking for! Adapted from bug report #29479 and code initially wrote by Midom for Wikipedia, the proctitle extension allows for a process to change its own displayed title in the system’s process list.

The extension (seen in action here) is an interface for making different sorts of daemons, including the ability to give them names. You can check out the project here.

tagged: pinetd proctitle extension daemon tcp udp name process fork

Link:

Doug Hill's Blog:
60 Days : What is it?
Dec 24, 2008 @ 18:33:35

Doug Hill has proposed a new project that he hopes to get the community behind - 60 Days:

60 Days is an idea I had while trying to decide what to do with the domains I have sitting around doing nothing — (well nothing but being a nagging reminder that I'll never have time for every idea that pops into my head, and that domain names cost money to keep).

The goal of the project is to take a domain you're not currently using (and you know you have some out there) and making something - a "real world project" - on it in 60 days. the catch is that, for each domain you use for the effort, it has to be a different PHP framework. Keep an eye out for the January 1 launch date for more details.

tagged: sixty days project effort domain name framework different realworld

Link:

David Otton's Blog:
Stupid PHP Tricks: Illegal Variable Names
Aug 22, 2008 @ 18:47:52

David Otton has shared another of his "stupid PHP tricks" on his blog today. This one looks at illegal variable names that don't match the "can't start with a number" rule the manual points out.

A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*'

Technically, you can get around this in two different ways - variable varaibles and the more complex notation with curly braces. He points to the compact function for proof that they're set.

tagged: variable trick illegal name compact curlybrace

Link:

Amir Saied's Blog:
PEAR bash completion
Jul 28, 2008 @ 17:08:29

Amir Saied recently posted a handy little tool for the PEAR users out there - a bash script that handles tab completion for you.

Lately I've been playing alot with the PEAR CLI. The one annoying thing I noticed the most was its lack of tab completion that I'm used to from the shell. It turns out that this feature is very easy to add, in the bash at least.

It will finish off the PEAR commands for you and expand out the PEAR package names and discovered channels when it finds a match. You can download the package here.

tagged: pear bash commandline completion tab package name channel

Link:


Trending Topics: