DOMDocument::registerNodeClass is great
PHP 5.2.0 comes with a new DOM function named
registerNodeClass()
. What is it good for? The documentation says
nothing as well as uncle Google. But this function is really great!
PHP 5.2.0 comes with a new DOM function named
registerNodeClass()
. What is it good for? The documentation says
nothing as well as uncle Google. But this function is really great!
I recently managed to speed up a PHP script to a hundredth of its original execution time by changing just a few characters in the source code. How is this possible? The drastic acceleration is due to the appropriate use of references and assignments. I'll let you in on how it works. Don't believe the sensational headline; it's not any kind of black magic. I repeat, you just need to understand how PHP works internally. But don’t worry, it's nothing too complicated.
The PHP core stores variable names separately from their values in memory. An
anonymous value is described by the structure zval.
Besides raw data, it includes information about the type (boolean, string, etc.)
and two additional items: refcount
and is_ref
. Yes,
refcount
is exactly the counter for the aforementioned reference
counting.
$abc = 'La Trine';
What does this code actually do? It creates a new zval
value in
memory, whose data section holds the 8 characters La Trine
and
indicates the type as a string. At the same time, a new entry abc
is added to the variable table, referring to this zval
.
Additionally, in the zval
structure, we initialize the
refcount
counter to one, because there is exactly one variable
($abc
) pointing to it.
For some, this is obvious, for me, it's mainly a cheat sheet. I just can't remember extremely long numbers, meaning those that have more than one digit.
In PHP, redirection is implemented with the following code:
$code = 301; // code in the range 300..307
$url = 'http://example.com';
header('Location: ' . $url, true, $code);
die('Please <a href="' . htmlSpecialChars($url) . '">click here</a> to continue.');
Note that after calling the header()
command, it is necessary to
explicitly terminate the script. It doesn't hurt to offer a text message and a
link for agents that do not automatically redirect.
The meanings of individual codes are described in detail in the standard RFC 2616: HTTP/1.1 Redirection. Here they are:
There are several URLs to which redirection is possible (pages may differ,
for example, in language). Offer users a list of these. The preferred
destination can be indicated in the Location
header; not every
browser automatically redirects. Rarely used.
Use this when a resource that used to exist at the requested URL is now
(permanently) located at a new address. Specify this in the
Location
header. However, if it has been discontinued, announce
this with the code 410 Gone.
A problematic code. It indicates that the resource has been temporarily moved elsewhere and the browser should access the new URL using the same method (GET, POST, HEAD, …) as used on the original. Additionally, with methods other than GET and HEAD, user confirmation should be required for the redirection. Most browsers, however, do not respect this and change the method to GET without requiring confirmation.
The code is often mistakenly used instead of 303.
The Post/Redirect/Get technique prevents double submission of forms upon page reload or back button click. After submitting a form using the POST method, a redirection is made using the GET method to another page. This is exactly what the 303 code is for, converting POST to GET.
For caching purposes. It responds to the If-Modified-Since header that the resource has not changed since the previous visit. The response must not contain a body, only headers.
As mentioned, code 302 has become problematic due to non-compliance with the standard by both web designers and browser creators. Code 307 is its reincarnation, which mostly works correctly. It can be used, for example, to perform a redirection using the POST method with transferred data.
This articles is actually an answer to e-mail by Honza Bien, who was asking me about the manipulations I was doing with conditional coments. Say, generally accepted idea is, that one kind of a comments (downlevel-hidden) is valid and the other (downlevel-revealed) is not. I tried to adapt those invalid comments the way that they would be valid. I'll explain the whole sequence.
Although flash is the most spread active element of webpages, a lot of designers still don't know the correct way to insert it into HTML document.. The standard concept, advertised by Macromedia is absolutely unusable.
Yes, the nomination for Texy is a really nice thing. It lets you learn many new and interesting insights, discuss things with nice people, and as they say, it moves you a bit forward.
To introduce the unsuspecting reader to the story: Texy is a little tool that I once programmed a long time ago (those were the days! I was still young and promising) and made it available for free to ease the blogging and web development for bloggers and developers. It became quite popular, running on many blogs, and unexpectedly entered a popularity contest among similar tools called Czech Open Source. This article is a showcase of the insults I’ve read because of it. I'm not someone who expects praise (even if it was deserved, bah! 🙂, but such an atmosphere doesn't really motivate…
Texy is no longer just sexy. František Brakon found new epithets:
I wonder WHO exactly selected the individual nominations. It must have been done in some closed group over beers, it’s not possible. How can, for example, the lame “one-evening” Texy and the global NetBeans be side by side?
Spalda proves the worthlessness of Texy using Google and the link operator:
For example, the previously mentioned CMS, if I consult brother Google: phpRS: 2,190,000 results, United-Nuke: 692,000 results, BlogCMS: 170,000 results
It’s definitely not used by just a handful of people, compared to the total fluke named Texy
Spalda continues to be upset that his favorite CMS was not nominated:
Otherwise, I only started promoting these CMS because when a fluke named Texy is nominated, these CMS rightfully deserve it many times over
Spalda deduces one poem:
The nomination of Texy nicely completes the level/profanation of the jury and thus the entire poll
Spalda is seriously troubled that I might even make a slight profit from Texy! (how could I, how could I?):
And when you brandish that Texy is free (as if everything else wasn’t free). We both know Texy isn’t so free… it's not much about selfless work for the community… but only about using the formulas of free software and open source to promote and sell commercial licenses
Millions of DONATE icons on all open-source project websites should be ashamed (Texy doesn't have one), let the MySQL price list blush in shame. Comrades, this is not how we build communism!
But then comes something that Spalda literally disarmed me with (just to add, I can't be blamed for the nomination, I don't know anyone from the jury and I certainly don't defend it):
Don’t you find it embarrassing to defend the nomination of something that took the place of something that deserved it more?
I was gasping for air, and when I finally caught my breath, the kicker came:
I understand that connections and business do their thing, but at least don’t smear it so vocally.
František Brakon reminds of an ugly spit recently left on Texy! by “someone” (RH):
You are right, Texy! is about an idea. And lo and behold, it could have occurred to anyone in the world. And indeed it did. Even before Texy saw the light of day, there was already the formatter Textile. And lo and behold, it has almost the same not only name but also syntax!
Dgx recently quarreled to the blood with he-who-must-not-be-named, who accused him of theft. The
discussion concluded that dgx obviously did not steal the source codes, but was inspired by Textile and achieved a similar result with his own code and added some extensions. Nonetheless, the brilliant idea of a “nowysiwyg editor” does not originate from dgx, and even the name could have been less eye-catching.
Words fail me. Yes, “NOWYSIWG” editors were here before WYSIWYG – they came with the invention of typewriters. Including all the entrenched conventions, which today I call Texy syntax. There’s no point in comparing who was first, but who is better. However, František Brakon has more serious objections to Texy:
The proposal seems like a hurrah action “I know regular expressions, let's try to write a parody of lexical syntactic analysis”. The only thing I can appreciate is the persistent effort for PHP4/5 compatibility. I appreciate it in the sense of “he sure struggled”, not in the sense of “that's good”. If you had given up on PHP4, the result would have been better. And you could have spared the comments and pieces of code php4_sucks. You probably didn’t want to lose the fame among lamers, dependent on questionable hostings.
In response to my note that Texy was created in November 2004, while the first usable version of PHP 5.0.4 dates to 31 May 2005, he responds
… in the changelog, I see “version 5.0.4 31-Mar-2005”, that’s 31 March 2005, you’re skewing it by two months. But let's not be prudish.
Incidentally, I don’t like narrow chests on women at all.
Thus, the first result of participating in a poll meant to promote open-source ideas and highlight domestic projects is that I have once again a huge desire to tell the entire open-source community to go to hell and never write another line ;)
Added 5 years later: today, I have a much bigger project (again for free), so there are even more insults 🙂 Personally, I find it rather funny, no kidding. My family sees it a bit worse. However, the fact remains that in our country, an unusual number of assholes need to rub against you, so I would recommend to all open source creators to throw a poop on their homeland, refuse participation in such dubious competitions, and create only in English, for abroad.
PHP currently supports property overloading provided by magic methods __get() and __set(). Those methods are called when accessed property is not declared in the class. Actually, this overloading is a bit frustrating.
This is my solution how to simulate properties with accessor methods in a Delphi way.
So…
// define new "like-keyword"
// value is short and unusual string
define('property', "\0\0");
Maybe _property
is a better choice. It doesn't matter now.
I have wrote tool for automatic convert PHP5 scripts to PHP4. It converts new PHP 5 object model features and language constructions into PHP 4 equivalents. This tool may be useful, if you need transfer PHP5 scripts to run under previous version. It is not designated to provides missing functionality (try PHP_Compat), just missing syntax.
Supported are these constructions:
Try it here
I spent a lot of time thinking, how to emulate some PHP5's object model features in older PHP4. How get rid tons of ampersands in my source codes. How force objects to not copy itself every time.
So, there is solution.
Texy! is now live and
is lively engaging with the world!
As I was reading your emails and feedback about Texy!, I realized that an interesting phenomenon has been born. Texy! has become a symbol, a Godot that many people have been waiting for, often impatiently. Some websites are counting on Texy! as the path of future development, others have even already deployed it. I read an opinion that Texy! will start a revolution in the CMS field and replace WYSIWYG editors. Conversely, another guy is asking whether Texy! will also have WYSIWYG? “I'm waiting for it like death!” was mentioned in the comments.
Given that until recently only one single article about Texy! was published and no one had seen it, this is an excellent score 🙂
So, from today, Texy! is officially out. Still in beta version, we need to iron out some bugs and fine-tune the syntax. Therefore, I will appreciate it if you put it through rigorous tests. The website itself is also in beta. I want to improve the texts, divide the Syntax page into several smaller ones, and maybe even add a forum.
I previously informed about choosing a license and eventually
chose a dual model – GPL + commercial license. So
you can use it for free for your needs (I would appreciate a link) and you can include it in your
GPL applications. And if you want to implement it in your commercial CMS,
contact me and we will arrange the conditions for a special license.
And not to forget: is there anyone with excellent knowledge of English (or another language) who would help me with translation for the price of publishing their name with a link and the ensuing eternal glory? Thanks 🙂
And a few more links: