 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
DevShed: PHP 5 Helpers Calling Methods Out of Object Scope
by Chris Cornutt July 27, 2009 @ 12:38:17
In this new tutorial from DevShed today they continue their series looking at making helper classes for your applications. This time they're focusing on using methods without needing to create an object first - static methods.
The methods of the class that I [just] mentioned were declared implicitly dynamic, even though it's perfectly possible to call them statically, and the PHP engine won't raise any errors about this process. However, it would be much better to declare these methods explicitly static, thus taking advantage of the functionality offered by the text helper class without having to spawn an instance of it.
They show how to define the methods with the "static" keyword so they can be called outside of the class' scope. Code for the helper class and the code to put it to use.
voice your opinion now!
method class object scope tutorial
Leonid Mamchenkov's Blog: Perl vs. PHP variable scoping
by Chris Cornutt December 12, 2008 @ 08:49:14
Leonid Mamchenkov has compared Perl versus PHP in this new blog post - specifically how they handle variable scoping.
I've mentioned quite a few times that I am a big fan of Perl programming language. However, most of my programming time these days is spent in PHP. The languages are often similar, with PHP having its roots in Perl, and Perl being such a influence in the world of programming languages. This similarity is often very helpful. However there are a few difference, some of which are obvious and others are not.
His example compares looping (a foreach in both) and how, after the Perl loop the $value variable is no longer accessible. In PHP, however, it's passed back out into the current scope and can be read just like any other variable. While this can be useful, it can also cause headaches when trying to track down elusive bugs.
voice your opinion now!
variable scope foreach loop local outside compare
Typical Programmer Blog: Doing it wrong getters and setters
by Chris Cornutt June 16, 2008 @ 11:19:17
According to this new post on the Typical Programmer blog, using getters and setters in your scripts only adds in a bit of unnecessary coupling and complexity to your scripts that you just don't need.
Today most of the popular programming languages support objects, limiting scope, modularity, passing by value, and sophisticated built-in types. There should be no reason to deliberately expose an object's data to the rest of the code because the language can enforce encapsulation and data hiding.
While not specific to PHP, the post does recommend against them because of one simple reason common to all languages that make them possible - they "break the encapsulation OOP offers". For them, they're like a cheat to get around bad coding practices and are not needed to make a successful application work.
voice your opinion now!
getter setter break object oriented encapsulation scope bad
SitePoint PHP Blog: Lexical scope to appear in PHP?
by Chris Cornutt December 25, 2007 @ 09:46:00
<>
In this new post to the SitePoint PHP blog, Troels Knak-Nielsen talks about some of the advancements (and diagreements) that have happened around adding lexical scope to the create_function functionality.
The main argument against approving the patch, seems to be, that one would expect static scoping rules to apply to the anonymous function. After all, this is the case in similar languages, which support anonymous functions. One could only assume, that changing PHP to support this, would be a major undertaking.
One would be wrong, it seems.
A patch has been made to add the functionality (from Christian Seller) adding a new keyword, lexical, to make it all work.
voice your opinion now!
lexical patch scope parse christianseller lexical patch scope parse christianseller
Arnold Daniels' Blog: Perl like temporary variables in PHP
by Chris Cornutt November 02, 2007 @ 09:38:00
Arnold Daniels points out a quick method for creating what he calls "perl-like temporary variables" in the global scope of a script:
When writing code in the global scope, I often have a problem where I'm overwriting a variable. This happens even more often when I work on code of somebody else. Usually has the variable which does the overwriting is usually just a temporary variable.
His code is a simple few lines that shows how it could be used when trying to write information out to a file handle. Some of the comments on the post criticize his use of the global scope but Arnold comes back with his reasoning - mostly that there is already code in the global scope and that adding something else is only adding to it, not making things worse.
voice your opinion now!
temporary variable perl global scope temporary variable perl global scope
PHP 10.0 Blog: More inlining
by Chris Cornutt November 20, 2006 @ 08:10:00
On the PHP 10.0 Blog, Stas talks more about inlining in PHP functions - some of the bad things this time (see here and here for other comments), including things that could break an application if not handled correctly.
Performance benefits from inlining simple functions might be significant, since function call in PHP is not cheap. We'd have some potential problems there.
Included in the list are things like:
- Variable scoping - we don't want function variables to mess with our scope, so we'd probably rename them or something.
- Then we might get a problem if function messing with current scope is called indirectly so we can't really know.
- And then some may use end-of-scope for destruction of variables that have dtors, so when we'd clean up these variables?
voice your opinion now!
inlining function performance benefit problem scope variable inlining function performance benefit problem scope variable
|
Community Events
Don't see your event here? Let us know!
|