Evert Pot422 Unprocessable Entity (23.4.2019, 15:00 UTC)

The 422 Unprocessable Entity status-code does not appear in the base HTTP specification. Like 102 and 207 it’s part of the WebDAV specification, which is an extension to HTTP.

Unlike the other two, the 422 code has a good general use-case, and is often used in Web API’s.

The 422 code implies that the server understood the general syntax of the request, but the contents were incorrect. For example, a server might expect POST requests that uses the application/json format. If the request is broken JSON, it might be more appropriate to send back the 400 status code, but if the request is valid JSON but the request doesn’t pass validation (via for example json-schema) returning 422 might be better.

If there was something wrong with the request body, you can use the following rules to figure out what to send back:

  • If the Content-Type was not supported, use 415.
  • Else: If the request was not parsable (broken JSON, XML), use 400 Bad Request.
  • Else: If the request was parsable but the specific contents of the payload were wrong (due to validation or otherwise), use 422

Example

POST /new-article HTTP/1.1
Content-Type: application/json

{ "title": "Hello world!"}

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/problem+json

{
  "type" : "https://example/errors/missing-property",
  "status": 422,
  "title": "Missing property: body"
}

References

Link
Voices of the ElePHPantInterview with Derek Binkley (23.4.2019, 11:00 UTC)

This episode is sponsored by

The post Interview with Derek Binkley appeared first on Voices of the ElePHPant.

Link
Derick RethansSignificant Symbols (23.4.2019, 08:27 UTC)

Significant Symbols

Last week a person on the #php IRC channel on freenode, mentioned that he had problems loading some extensions with his self-compiled PHP binary. For example, trying to activate the timezonedb PECL extension failed with:

sapi/cli/php:
        symbol lookup error: /usr/local/php/extensions/debug-non-zts-20180731/timezonedb.so:
        undefined symbol: php_date_set_tzdb

Which is odd, as the php_date_set_tzdb is a symbol that PHP has made available since Date/Time support was added. I asked the user to check whether his PHP binary exported the symbol by using nm, and the answer was:

$ nm sapi/cli/php | grep php_date_set_tzdb
000000000018bc75 t php_date_set_tzdb

The small letter t refers to a local only text (code) section: the symbol was not made available to shared libraries to use. In other words, extensions that make use of the symbol, such as the timezonedb extension can not find it, and hence fail to load.

In PHP, the php_date_set_tzdb function is defined with the PHPAPI prefix, which explicitly should mark the symbol as a global symbol, so that shared libraries can find it:

PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb)

The PHPAPI macro is used, because on Windows it is required to explicitly make symbols available:

#ifdef PHP_WIN32
#       define PHPAPI __declspec(dllexport)

On Linux (with GCC) symbols are made available unless marked differently (through for example the static keyword).

When looking into this, we discovered that his PHP binary had no exported symbols at all.

After doing a bit more research, I found that more recent GCC versions support a specific compiler flag that changes the default behaviour of symbol visibility: -fvisibility=hidden. In recent versions of PHP, we enable this flag if it is supported by the installed GCC version through a check in the configure system:

dnl Mark symbols hidden by default if the compiler (for example, gcc >= 4)
dnl supports it. This can help reduce the binary size and startup time.
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
                      [CFLAGS="$CFLAGS -fvisibility=hidden"])

As this makes all symbols hidden by default, the same commit also made sure that when the PHPAPI moniker is used, we set the visibility of these specific symbols back to visible:

#   if defined(__GNUC__) && __GNUC__ >= 4
#       define PHPAPI __attribute__ ((visibility("default")))
#   else
#       define PHPAPI
#   endif

When the original reporter saw this, he mentioned that was using an older GCC version: 3.4, and that he could see the -fvisibility=hidden flag when running make, just like here:

… cc -Iext/date/lib … -fvisibility=hidden … -c ext/date/php_date.c -o ext/date/php_date.lo

Because his GCC supported the -fvisibility=hidden flag, the check in the configure script enabled this feature, but because his GCC version was older than version 4, the counter-acting ((visbility("default"))) attribute was not set for symbols that are explicitly marked with the PHPAPI specifier. Which means that no symbols were be made available for shared PHP extensions to use.

The user created a bug report for this issue, but as GCC 3.4 is a really old version, it seems unlikely that this issue will get fixed, unless somebody contributes a patch. In the end, it was quite a fun detective story and to get to the bottom of this!

Become a Patron!
Link
PHP Scripts – Web Development BlogHow to validate the email address format in PHP? (22.4.2019, 15:00 UTC)

Receiving email messages via your website or web application is an important feature and often the only way to get in contact with your customers. If you look back, how often have you got an email message from a potential customer with an invalid or wrong email address? Sure you can use advanced regular expression […]

Originally published by Web Development Blog

Link
Anthony FerraraA PHP Compiler, aka The FFI Rabbit Hole (22.4.2019, 04:00 UTC)

It’s no secret that I’m into building toy compilers and programming languages. Today I’m introducing something that’s not a toy (I hope). Today, I’m introducing php-compiler (among many other projects). My hope is that these projects will grow from experimental status into fully production ready systems.

JIT? AOT? VM? What The Heck?

Since I’m going to be talking a lot about compilers and components in this post, I figure it’s good to start with a primer on how they work, and how the different types behave.

Types of Compilers

Let’s start by talking about the 3 main categories of how programs are executed. (There are definitely some blurred lines here, and you’ll hear people using these labels to refer to multiple different things, but for the purposes of this post):

  • Interpreted: The vast majority of dynamic languages use a Virtual Machine of some sort. PHP, Python (CPython), Ruby, and many others may be interpreted using a Virtual Machine.

    A VM is - at its most abstract level - is a giant switch statement inside of a loop. The language parses and compiles the source code into a form of Intermediary Representation often called Opcodes or ByteCode.

    The prime advantage of a VM is that it’s simpler to build for dynamic languages, and removes the “waiting for code to compile” step.

  • Compiled: The vast majority of what we think of as static languages are “Ahead Of Time” (AOT) Compiled directly to native machine code. C, Go, Rust, and many many others use an AOT compiler.

    AOT basically means that the full compilation process happens as a whole, ahead of when you want to run the code. So you compile it, and then some time later you can execute it.

    The prime advantage of AOT compilation is that it can generate very efficient code. The (prime) downside is that it can take a long time to compile code.

  • Just In Time (JIT): JIT is a relatively recently popularized method to get the best of both worlds (VM and AOT). Lua, Java, JavaScript, Python (via PyPy), HHVM, PHP 8, and many others use a JIT compiler.

    A JIT is basically just a combination of a VM and an AOT compiler. Instead of compiling the full program at once, it instead runs the code on a Virtual Machine for a while. It does this for two reasons: to figure out which parts of the code are “hot” (and hence most useful to be in machine code), and to collect some runtime information about the code (what types are commonly used, etc). Then, it pauses execution for a moment to compile just that small bit of code to machine code before resuming execution. A JIT runtime will bounce back and forth between interpreted code and native compiled code.

    The prime advantage of JIT compilation is that it balances the fast deployment cycle of a VM with the potential for AOT-like performance for some use-cases. But it is also insanely complicated since you’re building 2 full compilers, and an interface between them.

Another way of saying this, is that an Interpreter runs code, whereas an AOT compiler generates machine code which then the Computer runs. And a JIT compiler runs the code but every once in a while translates some of the running code into machine code, and then executes it.

Some more definitions

I just used the word “Compiler” a lot (along with a ton of other words), but each of these words have many different meanings, so it’s worth talking a bit about that:

  • Compiler: The meaning of “Compiler” changes depending on what you’re talking about:

    When you’re talking about building language runtimes (aka: compilers), a Compiler is a program that translates code from one language into another with different semantics (there’s a conversion step, it isn’t just a representation). It could be from PHP to Opcode, it could be from C to an Intermediary Representation. It could be from Assembly to Machine Code, it could be from a regular expression to machine code. Yes, PHP 7.0 includes a compiler to compile from PHP source code to Opcodes.

    When you’re talking about using language runtimes (aka: compilers), a Compiler is usually implied to be a specific set of programs that convert the original source code into machine code. It’s worth noting that a “Compiler” (like gcc for example) is normally made up of several smaller compilers th

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

Link
Voices of the ElePHPantInterview with Andrew Caya (18.4.2019, 11:00 UTC)

This episode is sponsored by

The post Interview with Andrew Caya appeared first on Voices of the ElePHPant.

Link
Derick RethansPHP Internals News: Episode 6: PHP Quality Assurance (18.4.2019, 08:06 UTC)

PHP Internals News: Episode 6: PHP Quality Assurance

In this sixth episode of "PHP Internals News" we talk to Remi Collet (Twitter, Website, GitHub, Donate) about the work that he does through RedHat and Fedora to improve the quality of PHP, PHP extensions, and PHP libraries and frameworks.

The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode's MP3 file, and it's available on Spotify and iTunes.

Show Notes

Credits

Music: Chipper Doodle v2 — Kevin MacLeod (incompetech.com) — Creative Commons: By Attribution 3.0

Become a Patron!
Link
larry@garfieldtech.comPSR-14: Example - plugin registration (17.4.2019, 23:08 UTC)
PSR-14: Example - plugin registration

In Content Management Systems and similar highly-configurable applications, a common pattern is to have a registration mechanism of some sort. That is, some part of the system asks other parts of the system "give me a list of your Things!", and then modules/extensions/plugins (whatever the system calls them) can incrementally build up that list of Things, which the caller then does something with. Those Things can be defined by the extension, or they can be defined by user-configuration and turned into a Thing definition by the module. Both are valid and useful, and can be mixed and matched.

This pattern lends itself very well to an Event system like PSR-14, and in fact the "give me a list of Things" pattern was one of the explicit use cases the Working Group considered. Today let's look at how one could easily implement such a mechanism.

Continue reading this post on SteemIt.

Larry 17 April 2019 - 6:08pm
Link
Matthew Weier O'PhinneyFrom Zend Framework To The Laminas Project (17.4.2019, 16:58 UTC)

Ten years ago this month, I was involved in a couple of huge changes for Zend Framework.

First, I helped spearhead integration of the JavaScript library Dojo Toolkit into Zend Framework, and finalized the work that month. I'd worked closely with the two developers who had been leading that project at the time, and one thing that came up during our discussions was that they had helped create an open source foundation for the project, to ensure its continuity and longevity, and to ensure the project can outlive the ups and downs of any commercial company. This idea intrigued me, and has stuck in the back of my mind ever since.

The other thing that happened that month was that I was promoted to Project Lead of Zend Framework. I've held that position ever since.

Today, I get to announce another change: Zend Framework is transitioning to an open source project under the Linux Foundation!

How Zend Framework Becomes Laminas

As I noted, I've been thinking about this for 10 years now, and actually doing research and trying to figure out a way to make it happen for almost two years. When my employer announced some restructuring of the Zend portfolio last fall, moving the project to a foundation was foremost on my mind.

So, imagine my surprise when an old PHP friend, John Mertic, reached out to me and offered the assistance of the Linux Foundation!

I had no idea that this was even a possibility. But, as it turns out, the mission of the foundation is to help create sustainable open source communities, and the primary way they do that is to help create foundations for projects. The beauty is that they take care of the business stuff that developers like myself don't have expertise in: legal issues, taxes, bookkeeping, and even help with things like marketing. They do this so that those of us working on open source projects can focus on our communities and our code. It's an absolutely perfect scenario for the project.

Over the last few months, I've worked with Rogue Wave (my employer) and the Linux Foundation to work out the logistics of this transition, including coming up with some initial budgets, helping flesh out a governance model, and identifying potential founding members. I've also worked with the Zend Framework community review team to come up with a name for the project, and work out some of the technical details for migrating both the project and its users.

So, please say a warm hello to the Laminas Project.

Laminas Project

What we announced today is just a beginning. The project is not yet operational. We're still working on tooling for migrating the project and its users, and, more importantly, recruiting more founding members. If your company is interested, please fill out our form, and we'll get back to you to discuss the details.

Acknowledgments

As a parting note, I need to acknowledge a number of people who helped me through the last few months:

  • My wife, Jen, who has been my chief sounding board, and helped me keep my sanity while I juggle meetings, emails, and growing task lists. Love you!
  • Enrico Zimuel, who has been my co-worker, confidante, and friend for years, and continued to help even when he left Rogue Wave last month. I'm excited for this new chapter!
  • The various folks in the Zend Professional Services team, for letting me bounce ideas off of them and occasionally voice my frustrations. You all know who you are!
  • The entire Zend Framework community review team: Rob, Gary, Marco, Frank, James, Evan, Adam, Aleksei, Andreas, Ben, Geert, Ryan, Michał, Michael, and Mike (yes, those last three are all different people!). In particular, Michał has been putting in crazy hours working on migration tooling, and Frank just this morning sent over changes for the Laminas website for me to incorporate!
  • John Mertic and Michael Dolan of the Linux Foundation for holding my hand through this entire process and helping make it happen. We still have work to do, but even getting this far feels like a huge accomplishment, and I couldn't have done it without your support.

If all goes to plan, I'm hoping we'll be announcing the project is operational in the next few months; keep an eye on the ZF and Laminas websites and twitter handles for updates!

mwopFrom Zend Framework To The Laminas Project was originally published 17 April 2019 on https://mwop.net by .
Link
Adam CulpZend Framework becomes Laminas project (17.4.2019, 14:16 UTC)

Today it was announced that Zend Framework is being rebranded as Laminas project. (drawn from the meaning “a thin layer”) Along with the rebrand comes some other important changes as well. Yes, this includes Expressive and Apigility, so continue reading.

Some History

Zend Framework is one of the largest and oldest PHP frameworks and has become a staple for enterprise development around the world. As of April 2019, it has over 400 million lifetime downloads of all packages associated with the project, which has seen a 4-fold increase in just the last 2 years alone. Despite this amazing track record, up to now the project has been supported and guided single-handedly by Zend Technologies, and later Rogue Wave Software.

Awesome Changes

Therefore, to continue this growth and receive the best support possible, the Zend Framework team is announcing that all projects under that umbrella will rebrand to a newly formed “Laminas” project“, which aims to continue their mission as an open source project hosted by the Linux Foundation. The transition will enable more companies to provide support for the projects they’ve come to depend on and help it continue to grow. As part of this transition, it is important for them to differentiate the open source project from the Zend commercial brand. Therefore, the new name “Laminas” project was created.

As part of this move, the Expressive microframework, Apigility api framework, as well as the MVC framework will all be part of the Laminas project.

I will try to add more details as they become available to us all, and will likely also do a Twitch stream and YouTube video with Beachcasts and that video can be viewed HERE.

Support Laminas Project

For more information, please see the new site dedicated to the Laminas project, and if you would like to become a member and/or support the project at the Linux Foundation (their blog post), please join and become a member.

Impact to current users

The framework team is working on scripts and tools to help users update namespaces and vendor packages with the renaming. See the video below for more info.

Beachcasts Video

I added this, and a little more content about the Zend Framework rebranding to Laminas project under the Linux Foundation. Check it out below.

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