News Feed
Jobs Feed
Sections




News Archive
feed this:

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

Lukas Smith:
__toString() or not __toString()?
August 28, 2013 @ 09:14:39

In Lukas Smith's latest post he looks at one of the magic methods that's built into PHP to help transform objects into strings - the __toString method. In the post he explores what it's for and what it might be used for.

The __toString() belongs to the family of methods and functions called "magic functions". They are magic because for the most part they do not get called explicitly but rather intercept operations. Unfortunately there are limits to its magic, specifically the only "context" the method is aware of is its design contract: to return a string. But its not clear what purpose that is. Should this be for some internal debugging or logging purposes? There one would be most interested in internal identifiers and object state. Is it for some frontend UI where the user will most likely be interested in some textual identifier that isn't too long as to not clutter the UI. There in lies the dilemma in the magic, while useful there is no way to ensure that the given context is passed on.

He looks at use cases for UI output (for consistent output) and contexts as well as the more internal-facing usage, like for logging and debugging purposes. Being able to get the context of the object as a string and pushed into a log at the time of error could be immensely helpful for debugging. He also links to some discussions happening on Twitter about the internal versus external uses of this magic method.

0 comments voice your opinion now!
tostring magicmethod usecase internal external

Link: http://pooteeweet.org/blog/0/2231#m2231

PHPMaster.com:
Understanding Streams in PHP
June 26, 2013 @ 10:43:45

PHPMaster.com has a new tutorial for those interested in how to work with streams, he base resources behind working with things like files and remote connections.

Streams are resources provided by PHP that we often use transparently, but which can also be very powerful tools. By learning how to harness their power, we can take our applications to a higher level. [...] Every stream has a implementation wrapper which has the additional code necessary to handle the specific protocol or encoding. PHP provides some built-in wrappers and we can easily create and register custom ones. We can even modify or enhance the behavior of wrappers using contexts and filters.

They start by introducing two of the most commonly used streams - "file" and "http" as well as some of the wrappers that can be used to work with them. He also talks about the "php://" stream, a special instance that lets you access things like a temporary memory block and stdout/stdin. He finishes up the tutorial with a look at "contexts" - the parameters that can be used to modify the stream wrapper (like his HTTP example).

0 comments voice your opinion now!
tutorial streams introduction file http internal

Link: http://phpmaster.com/%EF%BB%BFunderstanding-streams-in-php

Andrew Podner:
Using Stackato for PHP Applications in a Private PaaS
March 18, 2013 @ 12:17:51

In this new post to his site Andrew Podner looks at using the Stackato software from ActiveState to provide a Platform-as-a-Service environment on any cloud infrastructure.

So, now it is settled, I want to stay inside the corporate firewall, but I want each application isolated from the next, and by the way, there is no budget for any of this. I posted about three PaaS providers a while back, and started thinking that what I really needed was PaaS, but I needed to be able to host the PaaS environment inside a corporate LAN. Off to search the web. Surprisingly, there were not just a ton of viable results in that search. Even more surprising...hard to find one with a "download here" button. No matter how I searched though, one company & product kept popping up: Stackato by ActiveState. The words "Free Micro Cloud" were a very encouraging sign. So let's take this thing for a spin and see just how easy it is...

He walks you through the installation process - downloading the VMs, setting up the initial configuration and how to use the command line tool to deploy your own applications (several come preconfigured though). He also includes an example configuration (YAML) you can use to configure custom applications and some sample code showing a database connection.

0 comments voice your opinion now!
activestate stackato paas private internal review tutorial


Nikita Popov's Blog:
Understanding PHP's internal array implementation (Part 4)
March 29, 2012 @ 09:16:02

Nikita Popov has posted the fourth part of the "PHP's Source Code for PHP Developers" series he and Anthony Ferrara have been posting. In this latest article in the series, Nikita looks specifically at PHP's array implementation and how it's handed "behind the scenes".

Welcome back to the fourth part of the "PHP's Source Code for PHP Developers" series, in which we'll cover how PHP arrays are internally represented and used throughout the code base.

He starts with an obvious foundation: "everything's a hash table" (even properties, classes and yes, arrays). He describes what a hash table is and talks about two of the most commonly used versions of it in the PHP source - HashTable and Bucket. He gets into their usage a bit and compares this to the corresponding PHP code that uses a standard array.

0 comments voice your opinion now!
source code developers language internal array hashtable bucket


Nikita Popov's Blog:
Understanding PHP's internal function definitions (Part 2)
March 19, 2012 @ 08:17:48

Following this recent post from Anthony Ferraara about the source code of the PHP language itself, Nikita Popov is working with him and has produced the second part of the series, a look at finding the internal function definitions for the PHP functions you use every day.

In the previous part ircmaxell explained where you can find the PHP source code and how it is basically structured and also gave a small introduction to C (as that's the language PHP is written in). If you missed that post, you probably should read it before starting with this one. What we'll cover in this article is locating the definitions of internal functions in the PHP codebase, as well as understanding them.

He starts with a basic example - a string function, strpos. He shows a handy searching trick to help find the actual function definition and which matches should be given priority. He lays out a typical skeleton of a PHP function definition and gets into some detail as to what this particular function does (in C). He briefly mentions the Zend Engine functions and a look ahead to finding classes and methods.

0 comments voice your opinion now!
source code developers language internal function definition tuttorial


Brandon Savage's Blog:
An XSS Vulerability In The Making
March 07, 2012 @ 12:02:46

Brandon Savage has a new post to his blog about what he calls a XSS vulnerability in the making, something to watch out for when you're doing validation in PHP involving the possibility of numbers as strings.

Back in September, Socorro received a security bug relating to the method we were using for processing inputs for the duration of certain reports. The vulnerability included a proof of concept, with an alert box popping up on production when the link was followed. [...] I was quite surprised at the root cause of the vulnerability. We had opted to compare the incoming data against a known set of valid values - a common practice when whitelisting certain inputs. [...] As expected, when this [example] code is tested, a string of '3' and an integer of 3 work equally well, and a string of '5' and an integer of 5 fail equally.

This automatic casting that PHP does internally caused another issue as well - if the string passed in even started with a valid number from their whitelist set, it still passed.

At first we thought this surely had to be a bug in PHP. However, Laura Thomson told me "If comparing two values, type juggling is performed first, which means that the string is converted to a number. This is done by taking the first number found in the string. So this may be confusing/a quirk/a gotcha, but it isn't a bug." And she's right: this isn't a bug per se, but it's certainly an interesting "gotcha."
0 comments voice your opinion now!
crosssitescripting xss type juggling string conversion internal


Alexey Zakhlestin's Blog:
on PHP's webserver
March 03, 2011 @ 13:19:04

Alexey Zakhlestin has a new post today with some of his own thoughts on the suggestion for a built-in web server (RFC) that's been floating around lately - a tool that would act as a simple server right out of the box without much in the way of configuration.

There are a lot of talks today about "Built-in web server" [for PHP] RFC by Moriyoshi Koizumi. There is a nice discussion on Hacker News (and 2 threads on reddit: here and here). So, here's couple of cents from me.

Alexey agrees with the suggestion and notes it'd be a welcome addition to the PHP toolset. He also reminds developers that it wouldn't (and shouldn't) be used in production.

0 comments voice your opinion now!
opinion webserver internal rfc suggestion


PHPBuilder.com:
PHP Developer Resources
November 21, 2008 @ 08:07:39

PHPBuilder.com has posted a list of resources that they offer to help both beginning and experienced PHP developers to further their knowledge:

PHP is one of the most popular scripting languages used to develop applications on the web today. As a result, internet.com has a multitude of PHP resources throughout our network of websites. Here are some of our best PHP resources, along with some featured tutorials and out-of-network resources that you may not know about.

The grouping of links also include external resources like the main PHP site and Zend's website.

0 comments voice your opinion now!
developer resource list link internal external zend


Greg Beaver's Blog:
PHP namespaces become much better (Derick take note)
June 23, 2008 @ 11:19:27

Greg Beaver, noting some issues that Derick Rethans had pointed out about namespace support for upcoming PHP versions, has posted about a patch he submitted to solve the problem simply.

The issue Derick pointed out:

In PHP 5.3 this would alias the class Interval in the namespace PEAR::Date to the class Interval. For now, this code would work just fine. However, if PHP would introduce a class "Interval" at some point in the future (and PHP can do this as it owns the global namespace) then the above code would suddenly stop working.

Greg's patch makes it possible to "override" the internal class if need be, making it so that code currently working wouldn't break. All it takes is to "use" is like you normally would and and the magic happens behind the scenes.

0 comments voice your opinion now!
namespace override internal class instance patch php5


Dokeos Blog:
mbstring vs iconv
April 24, 2008 @ 11:18:08

In this post on the Dokeos blog, there's a comparison of the mbstring function and the iconv library as it pertains to their use on multi-byte strings.

I was wondering today why use mbstring rather than iconv in Dokeos, and honestly I didn't remember exactly why I had chosen mbstring in the past, but finding information about the *differences* between the two. [...] Searching a bit more, I found a PPT presentation from Carlos Hoyos on Google.

Essentially, it boils down to how the library is integrated - mbstring is bundled and iconv is pulled from an external source. So, if you're looking for maximum portability, he recommends mbstring.

0 comments voice your opinion now!
mbstring iconv multibyte character string compare internal external



Community Events











Don't see your event here?
Let us know!


install performance hhvm opinion application symfony2 composer security podcast release support component hack unittest facebook database introduction package language framework

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework