-
Hello World Snippet
Hello World Snippet demonstrating the simpliest PHP application
Jakub Míšek
Friday, 24 March 2017 -
PHP variables
Small example snippet with PHP variables
Ben Fistein
Friday, 24 March 2017 -
Leibniz Pi
This snippet contains the formula for calculating Pi in PHP.
Ben Fistein
Saturday, 25 March 2017 -
Method calling microbenchmark
Small test sample to microbenchmark method calling
Ben Fistein
Saturday, 25 March 2017 -
Type-safe usage demonstration
Peachpie provides an incredibly fast compile time check and creates typed interfaces for .NET languages, allowing for a type safe use.
Ben Fistein
Saturday, 25 March 2017 -
Property assignment test code
This code was used to microbenchmark property assignment with Peachpie against standard PHP.
Ben Fistein
Saturday, 25 March 2017 -
Include_once
Demonstrating how include_once is compiled.
Ben Fistein
Saturday, 25 March 2017 -
Conditional declaration
This snippet includes a conditional declaration of a function, which is quite unusual in modern programming languages. Such a piece of code has to be supported by the compiler and the runtime as well.
Ben Fistein
Saturday, 25 March 2017 -
Include test
Small snippet to demonstrate how 'include' is compiled to MSIL and decompiled to C#, see http://www.peachpie.io/2016/05/the-net-effect.html.
Ben Fistein
Saturday, 25 March 2017 -
Static local variables
Sample snippet demonstrating how Peachpie compiles static locals in this article: http://www.peachpie.io/2016/05/static-locals.html.
Ben Fistein
Saturday, 25 March 2017 -
Static locals
This snippet shows the two basic usages of static locals: counting something and checking to ensure that we do not enter into a function more than once
Ben Fistein
Saturday, 25 March 2017 -
Foreach
Foreach is a powerful construct in PHP, see this article: http://www.peachpie.io/2016/06/foreach.html.
Ben Fistein
Saturday, 25 March 2017 -
Static fields
Every bunch of static fields is represented as a nested class named "_statics", whose instance is lazily bound to a web request, represented as a Context class in Peachpie. Then, by accessing a static field of a class, the compiler actually generates code that retrieves instances of "_statics" from Context and accesses its instance (non-static) fields. For more information on this, please refer to http://www.peachpie.io/2016/06/static-fields.html .
Ben Fistein
Saturday, 25 March 2017 -
Sample Azure script
This sample script was used to benchmark PHP on Microsoft Azure in this article: http://www.peachpie.io/2016/07/azure.html.
Ben Fistein
Saturday, 25 March 2017 -
Second pass - with strong type information
Second pass from our standard benchmark with strong type information: http://www.peachpie.io/2016/07/standard-benchmark.html.
Ben Fistein
Saturday, 25 March 2017 -
Sample compilation optimization snippet
This optimization avoids repetitious memory copying. Since call_user_func_array() takes an associative array that has to be internally copied into a simple array, we shall use call_user_func() instead. It takes .NET params as a flat array already.
Ben Fistein
Saturday, 25 March 2017 -
Replacing call_user_func() with an actual functions call
Just to see the overhead of dynamic calls caused by constant lookups into hashtables, let us get rid of call_user_func() completely. We will replace it with an actual functions call.
Ben Fistein
Saturday, 25 March 2017 -
SimpleDog class snippet
Here you can see a 'SimpleDog' class and 'goodboy' global function in PHP. Notice the well-known PHPDoc annotation '@param' that we use to mark the function parameter's type, which means that the compiled methods have a specific CLI type.
Ben Fistein
Saturday, 25 March 2017 -
"Hello World" mini snippet
Tiny "Hello world" snippet
Ben Fistein
Saturday, 25 March 2017 -
Syntactic sugar
This code exemplifies syntactic sugar generated by Peachpie compiler.
Ben Fistein
Saturday, 25 March 2017 -
Referencing .dll from PHP
The dependencies in a .NET dll become seamlessly available to the PHP code with Peachpie. The compiler takes care of this process and allows you to use the C# symbols in PHP. See this article: http://www.peachpie.io/2016/12/php-dotnet-csharp-interoperability.html.
Ben Fistein
Saturday, 25 March 2017 -
Declaration injection at runtime
Peachpie allows you to define PHP global functions as C# lambdas dynamically at runtime. You can use a non-existing global function in your PHP code, so the compiler postpones its direct call by using 'Call Sites'. Then, we provide the function definition in the runtime before the call is made so that the runtime uses your provided method.
Ben Fistein
Saturday, 25 March 2017 -
Include of a non-compiled content file
The line 'require_once( $svg_icons )' allows one to upload a file onto the host's server if not otherwise handled. Peachpie actually helps in this case, as we do not allow the Include of a non-compiled content file. The compiler recognizes that WordPress performs a Require on a file that had originally not been compiled. Rather than running it, which can potentially be harmful, it merely inserts its content into the site.
Ben Fistein
Saturday, 25 March 2017 -
Class extending conditionally declared class
As of Peachpie version 0.5.0, the compiler did not support classes extending a class that is declared conditionally, such as this code snippet.
Ben Fistein
Saturday, 25 March 2017 -
Syntax error snippet
This snippet is used to demonstrate a syntax error
Ben Fistein
Saturday, 25 March 2017 -
Warning example snippet
This snippet shows a green underlining for a warning/recommendation.
Ben Fistein
Saturday, 25 March 2017 -
Tooltip example snippet
This snippet serves as an example of how tooltips are displayed.
Ben Fistein
Saturday, 25 March 2017 -
Standard benchmark - first pass
First warmup pass from our standard benchmark: http://www.peachpie.io/2016/07/standard-benchmark.html.
Ben Fistein
Saturday, 25 March 2017 -
Anonymous classes
Support for anonymous classes was added in PHP 7. Anonymous classes are useful when simple, one-off objects need to be created.
Ben Fistein
Saturday, 25 March 2017 -
Send Mail using mail function in PHP
Send Mail using mail function in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Base64 Encode and Decode String in PHP
Base64 Encode and Decode String in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Get Remote IP Address
Get Remote IP Address in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Get IP address if client is behind proxy server
Get remote IP address in PHP if client is behind proxy server.
Ben Fistein
Sunday, 26 March 2017 -
Seconds to strings
This function will return the duration of the given time period in days, hours, minutes and seconds. e.g. secsToStr(1234567) would return “14 days, 6 hours, 56 minutes, 7 seconds”.
Ben Fistein
Sunday, 26 March 2017 -
Email validation
Snippet to validate an email in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Parsing XML easily
Required Extension: SimpleXML
Ben Fistein
Sunday, 26 March 2017 -
Database connection
Database connection in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Generate authentication code
This basic snippet will create a random authentication code, or just a random string.
Ben Fistein
Sunday, 26 March 2017 -
Date format validation
Validate a date in “YYYY-MM-DD” format.
Ben Fistein
Sunday, 26 March 2017 -
HTTP redirection
HTTP redirection in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Directory listing
Directory listing in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Browser detection script
Browser detection PHP script.
Ben Fistein
Sunday, 26 March 2017 -
File unzipping
Unzip a file in PHP.
Ben Fistein
Sunday, 26 March 2017 -
Random color
Generates a random hex color (like FF00FF).
Ben Fistein
Sunday, 26 March 2017 -
Sanitize database inputs
When inserting data in your database, you have to be careful about SQL injections and other attempts to insert malicious data into the database. The function below is an efficient way to sanitize a string before using it with your database.
Ben Fistein
Sunday, 26 March 2017 -
Email error logs to yourself
Instead of publicly displaying possible errors on your website, you can use a custom error handler to email error logs to yourself with this snippet.
Ben Fistein
Sunday, 26 March 2017 -
Send an SMS
For sending SMS using any language, you’d need an SMS gateway. Most of the SMS providers these days provide with an API. For the below PHP snippet, MSG91 is used as an SMS gateway. As of March 2017, Peachpie doesn't support cURL yet.
Ben Fistein
Monday, 27 March 2017 -
Preventing SQL injection
An SQL injection is a common technique used to hack into a website. Using the below code can help you prevent it.
Ben Fistein
Monday, 27 March 2017 -
Find out a website's source code
Use this function to be able to get the HTML code of any webpage.
Ben Fistein
Monday, 27 March 2017 -
Generating CSV
The following code wraps logic to construct CSV output from an array of data. It has optional parameters to allow for header columns and whether to flush the CSV directly to the browser or return the output as a string. The elegance here is the usage of streams with fputcsv() as the function requires an open file handle to operate.
Ben Fistein
Tuesday, 28 March 2017 -
Check if server is HTTPS
This code allows you to check if your script is running on a server with HTTPS.
Ben Fistein
Tuesday, 28 March 2017 -
Get percentage
Use this snippet to calculate the percentage of a certain value in our project.
Ben Fistein
Tuesday, 28 March 2017 -
Array operator example
This snippet is taken straight from the PHP manual, showing how array operators work.
Ben Fistein
Wednesday, 29 March 2017 -
Create a tag cloud
This snippet creates a tag cloud, including a sample usage at the end.
Ben Fistein
Thursday, 30 March 2017 -
Evil Eval 1
Show of use of eval() and dynamic declaration of a class. Note this is dangerous and should not be used in production. Snippets show a corresponding warninig message.
Friday, 31 March 2017 -
Eval test #1
This short snippet was used to test eval().
Ben Fistein
Saturday, 08 April 2017 -
Eval test #2
This snippet was used to test the eval() function.
Ben Fistein
Saturday, 08 April 2017 -
PHP Sessions
Short snippet showing our implementation of PHP sessions.
Ben Fistein
Sunday, 23 April 2017 -
PHP Generators
Quick snippet showing the initial support for generators.
Ben Fistein
Sunday, 23 April 2017 -
PHP Generator snippet
For use in 0.7.0 article, showing our initial support of generators.
Ben Fistein
Sunday, 23 April 2017 -
Diagnostics error message
Short snippet demonstrating meaningful error messages for unsupported constructs.
Ben Fistein
Sunday, 23 April 2017 -
Type analysis update
Newest type analysis features for blog post.
Ben Fistein
Monday, 12 June 2017 -
Unreachable code analysis
Latest unreachable code analysis for blog post
Ben Fistein
Monday, 12 June 2017 -
Optimized/not optimized for loop
This snippet shows one foor loop with an optimized control variable and one without.
Ben Fistein
Wednesday, 21 June 2017 -
Argument unpacking
Short snippet used for a blog post.
Ben Fistein
Sunday, 02 July 2017 -
call error
Invoking a member function on a non-object detected in compile time.
Jakub Míšek
Wednesday, 26 July 2017 -
Iterator/Generator
Used for a blog post
Ben Fistein
Wednesday, 09 August 2017 -
Array access
Used for a blog.
Ben Fistein
Wednesday, 09 August 2017 -
PHP array
Short snippet to be used in our blog about array optimizations.
Ben Fistein
Tuesday, 31 October 2017 -
Instanceof $this converts $this to string
Test case with an unexpected result.
Ben Fistein
Saturday, 02 December 2017 -
Yield from example
Small snippet showing Peachpie's implementation of `yield from`.
Ben Fistein
Sunday, 14 January 2018 -
Traits
Trait example
Ben Fistein
Sunday, 14 January 2018 -
Trait example
Mini trait
Ben Fistein
Sunday, 14 January 2018 -
Peachpie version checking
This snippet checks whether your code runs on Peachpie and if so, on which version, and then outputs a corresponding message.
Ben Fistein
Monday, 15 January 2018 -
Razor Partial View in PHP
Used for our blog post.
ben@iolevel.com
Friday, 03 August 2018 -
Razor Partial View
Used for our blog
Tuesday, 07 August 2018 -
crypt example
Example of crypt() function.
Jakub Míšek
Thursday, 23 March 2017 -
sample User and method call
calling method on new expression
Jakub Míšek
Thursday, 23 March 2017 -
dependency injection
this is how we do dependency injection
Jakub Míšek
Friday, 24 March 2017