How different are Javascript and PHP

Day: php

Visual Studio Code: cross-platform editor for developers

On the occasion of Build 2015 Microsoft presented a really interesting project for web developers: Visual Studio Code is the name of a new, free and cross-platform (Windows, Mac OS X, Linux) development environment aimed at web developers. The editor is based on Electron (previously Atom Shell) and thus on Node.js, HTML and CSS. Nevertheless, it offers everything a developer could want: bracket matching, IntelliSense, multi-cursor support, parameter hints, snippets, breakpoints, Git integration and much more. The application gives developers 3 themes to choose from and configuration is possible directly by editing JSON files.

Although Visual Studio Code is currently only available in version 0.1.0, it has already proven itself to be the ultimate tool for Node.js apps: Node.js applications can be started and analyzed easily at the push of a button (breakpoints, step-through, etc.) and the current variables are displayed in real time in the sidebar. Microsoft should have achieved a small breakthrough with this, because the tool is very extensive despite its compactness. All web languages ​​(HTML, JavaScript, CSS, Less, Sass, TypeScript, PHP, CoffeeScript, Go, Handlebars, Markdown, Python, Ruby, SQL, YAML, etc.) are supported and due to its adaptability Visual Studio Code could already soon to become the standard in free editors for web developers. Of course there is still GitHub's Atom and Facebook's Nuclide could also be interesting.
And Visual Studio 2015 will also be tough: According to a blog post, they want to focus more on the development of mobile apps. So far, Apache Cordova and Xamarin have been mentioned here. So it remains exciting.

PhpFiddle: Run PHP / MySQL snippets online

There are now several online editors for a number of programming languages: Ideone or Compilr would be well-known representatives of this type. Tools such as JS Bin, JSFiddle or CodePen have established themselves for JavaScript / HTML / CSS. PHP developers who want to try out a code snippet directly in the browser or who want to send a colleague a MySQL function should take a look at PhpFiddle. In principle, this is the equivalent of JSFiddle, only for PHP.

The online PHP editor comes with various API connections and offers the option of integrating known libraries. In addition, SOAP and XML-RPC services can be controlled and the use of MySQLi, PDO and PHPMailer is also possible. PhpFiddle should be particularly interesting for quick testing of MySQL queries: the code for the connection to the test database can be loaded with a click. Furthermore, the PHP code can be validated by a number of sniffers (PEAR, Squiz, Zend, etc.). A security test suite for checking possible security gaps (CSRF, RFE, XSS, DT, LFI, SQL injections) is also available.
Finally, there is also a slimmed-down version that is available as PhpFiddle Lite and offers a less complex surface.

reSRC: Collection of free books on programming

What would you like to order? A digression into graphics programming with DirectX, OpenGL and shaders? Or is it more the areas of software architecture, databases, operating systems and data mining? The list of the different subject areas and programming languages ​​alone seems to be endless: At reSRC there is the "List of Free Programming Books" that makes developers' hearts beat faster. There should really be something for every programmer here.

In addition to language-independent areas, some of which have already been listed above, there are links to free PDF eBooks or websites for pretty much every programming language: From ASP.NET and Assembler to C ++, CoffeeScript and Dart, past Erlang, Go, Haskell, JavaScript and Lua up to Objective-C, PHP, Processing, Python, Ruby, Scala, SQL or even TypeScript. There are now even sub-areas for JavaScript such as Knockout.js, AngularJS, Backbone or node.js. So it's worth browsing.

Web development: PHP version 5.4.0 released

The developers behind PHP recently released version 5.4.0 of the scripting language. With this version various innovations were introduced and old relics were buried: Among other things, the INI directives "safe_mode", "magic_quotes_gpc" and "register_globals" have been removed, which should please many PHP developers. There are also new language functions that can accelerate the development of PHP applications. So arrays can now be created with:

  • // Numerically indexed
  • $ arrayA = [1, 2, 3, 4];
  •  
  • // associative
  • $ arrayB = ["one" => 1, "two" => 2, "three" => 3];

Furthermore, array elements can be referenced directly when a function is called, such as. In addition, class objects can be addressed as soon as they are instantiated.

A list of the new features can be found here and the newly introduced functions are available on this page. Another feature is traits that make code easier to reuse. This means that methods and attributes can easily be transferred to a class, which corresponds to a simplified inheritance.
The new PHP version is available for download here and instructions for migration can be found on this page.

Web Development: Effective URL Expressions in PHP

In web applications, validations are an important topic that cannot always be solved easily at first glance. While HTML5, for example, already has a ready-made attribute for validation for input fields, separate solutions are required for other scenarios. For example, a popular check that is a little more difficult to create would be URL validation. Corresponding masking should be made here using regular expressions so that dangerous entries or attempted workarounds are not passed on to the application or the database.
Mathias Bynens has put together a matrix on this subject in which predefined URLs are validated using different expressions.

In the headers of the table are the authors of regular expressions, which work differently well. Every regular expression has a different length: While the Spoon Library requires 979 characters, Diego Perini's expression only uses 502 characters. Its validation also includes the use of IP addresses in the range 1.0.0.0 to 223.255.255.255. The "S" modifier was used in the tests to increase speed, but should not be used in a productive environment.
When validating, it is also important to check the HTTP protocol and thus the "http: //" prefix. There is a separate table for this area in the overview, in which various examples of possible URLs are listed.

HamlPHP: Use Haml templates in PHP

Anyone who has already worked with Ruby or Rails will be familiar with the "ERB" template system. The metalanguage makes it possible to implement and evaluate Ruby source text in HTML templates. The whole thing is even shorter with Haml (HTML Abstraction Markup Language), a simplified markup language that is primarily available as a Ruby Gem. With Haml, HTML templates can be written even more compactly and still be equipped with dynamic areas. A characteristic of the language is the evaluation of indentations (spaces), which have an impact on the semantic structure of the document.
In the meantime, implementations of the Haml syntax are also available for PHP and is a representative of them.

The project consists of different classes and creates a temporary PHP file after parsing a Haml template, which is then interpreted and displayed in the browser. The HamlPHP parser can be used as follows after integrating the appropriate classes:

  • $ content = $ parser-> parseFile ("template.haml");

A Haml template could then look like this:

  • !!! 5
  • % html
  • % head
  • %body
  • #Container
  • % h1 {"id" => "header"} Headline
  • % a {href => "http://haml.info/"} Haml website

The final edition:

  • <!DOCTYPE html>
  • <html>
  • <head></head>
  • <body>
  • <div id="container">
  • <h1 id="header">Headline</h1>
  • </div>
  • <a href="http://haml.info/">Haml-Website</a>
  • </body>
  • </html>

Any attributes can be set and CSS, JavaScript or PHP areas can also be integrated via certain masking. PHP evaluations can also be carried out directly using a special syntax which is called "interpolation" in HamlPHP.
The package also contains a number of examples and if you want to try Haml directly, you can use the area on the official website.

UPDATE
The project no longer exists in this form.

Hyperpolyglot: script languages ​​in direct comparison

Anyone who works as a web developer has the choice of which scripting language to use, depending on the project and server environment. The decision should depend primarily on existing experience and the requirements of the project. With PHP, Ruby, Python and Perl, there are several scripting languages ​​to choose from that can be used for web applications. The hyperpolyglot overview could be a small aid to decision-making, which shows the differences between the languages ​​similar to my JavaScript Framework Matrix.

The "Side-by-Side Reference Sheets" represent a table in which each script language corresponds to a column. In the lines there are different behaviors and properties of the respective language. These generally include block limits, assignments, operators, scoping, global variables, constants or comments. The table is divided into several areas such as logic, arrays, regular expressions, functions, processes, objects, reflection or debugging. So there are corresponding code examples for all scripting languages. A click on a property leads to the definition so that all terms can be looked up. There is also background information on the various languages.
Incidentally, the matrix is ​​only a decoupling of the entire overview from Hyperpolyglot: Here you can find reference sheets for almost all programming languages.

PPI Framework: Flexible MVC library for PHP

If you can't quite decide which PHP framework should be used for the next project, you should take a look at a comparison or a matrix that shows the features of large libraries. If it can be a bit more compact, less popular frameworks also do a good job. The PPI framework, for example, is designed for both small blog systems and extensive e-commerce projects and, in addition to the MVC structure, offers solid features with which sessions and request data can be processed and caching mechanisms can be integrated.

The library contains a bootstrapper that is responsible for the basic configuration:

  • include ('../ ppi / init.php');
  • $ app = new PPI_App ();
  • $ app-> boot () -> dispatch ();
  •  
  • system.base_url = http: // localhost / mysite /
  •  
  • system.masterController = home

A master controller can also be defined here, which is called as soon as no route is defined in the URL.
The routing is very easy to understand and can look something like this:

  • // File: App / Controller / User.php
  • class APP_Controller_User extends APP_Controller_Application {
  •  
  • function index () {
  • echo 'Hello Index';
  • }
  •  
  • function profile () {
  • echo 'Hello Profile';
  • }
  •  
  • }

Here the methods are mapped on the following routes:

  • http: // localhost / myapp / user
  • http: // localhost / myapp / user / index
  • http: // localhost / myapp / user / profile

The PPI framework supports different template engines and so templates can be written in common PHP, Smarty or Twig. In the documentation, the remaining functionalities of the framework are highlighted and the current version of the project as well as offline documentation can be downloaded in the download area.