Posts

Showing posts from March, 2009

[PHP] Strict error on static call? Solved!

Just a quick post about Strict standard error when we have a class method which would like to behave differently if called statically. Apparently, and this is a truly old bogus I opened ages ago , the solution was to supress Strict errors (lol, thanks developers) even if in every other programming language, via overload, this kind of situation could be solved in a bit. How to solve the problem? While last post I suggested a couple of runtime solutions, this time I suggest to simply avoid the method definition and use a different one with a meaningful name. In this example I created a String class: class String { // choose a recognizable name for protected method static protected function _concat(array $arguments){ return new self(implode('', $arguments)); } // use magic __callStatic function static public function __callStatic($name, array $arguments){ // check the recognizable name switch($name = '_'.$name){ ...

[js.php] A JavaScript Object Like PHP Class

PHP 5.3 introduces the Closure class which is really useful and more powerful than good old lambdas via create_function . These are main limits of Closure class: you cannot serialize a Closure instance (and json_encode does not solve the problem at all) you cannot inject scopes via $this unless the closure comes from a class method While with an emulated prototype style class, something I tried months ago as well, the first point could not be a problem, to solve the second one is quite inevitable to use a Python like variable as first argument, called $self , to make the Closure both portable and re-adaptable. JSObject :: JavaScript Object Like PHP Class /** js.php basic JSObject implementation * @author Andrea Giammarchi * @blog WebReflection.blogspot.com * @license Mit Style License */ class JSObject implements ArrayAccess { // public static prototype static public $prototype; // ArrayAccess Interface public function offsetExists($index){return isSet(...

[IE8] Global constants via defineProperty ... Illusion!

I do not want to spend a single word about Internet Explorer 8 Object.defineProperty implementation, which works only with DOM prototypes and the super global window but not with user defined objects , as __defineGetter__ and __defineSetter__ do since ages : Standards are an important factor to ensure browser interoperability for the Web developer (n.d. oh, really?!??!?!!!!) . The accessor property syntax has only recently begun standardization (you guys have a weird concept of the time ... or the meaning of "recent" in IT therms ...) . As such, many browsers support an older, legacy syntax ... (n.d. which at least has dignity to work with every kind of object ... ) Anyway, few things are better than nothing, so welcome to Object.defineProperty! Let IE8 behaves like every other or change every other to respect new M$ standard? This was the first question when I thought about this new global function: does it mean we finally have a way to emulate __defineGetter__ and setter in...

noSWFUpload - Zero Plug-In Multiple Upload

Image
As announced a couple of days ago, I am finally proud to introduce my last library free Multiple Upload Component , now compatible with every browser and always without usage of 3rd parts plug-ins. This little project has been hosted in Google Code and I promise I'll write there a complete documentation asap. Righ now, you can read the project source code via zip to understand what he little API is doing. Update I added a couple of sections in the Wiki page ;) Compatibility? Internet Explorer 5.5 (probably 5 too), 6, 7, and 8 FireFox? 3 or greater Google Chrome 1.0 Opera 8, 9, and 10 Safari 4 (current beta) other browsers via unobtrusive iframe Try the demo if you do not believe it :P

packed.it ... bye bye my darlin'

I spent a month about two years ago to create packed.it , which has been used by few developers, which cannot compete with other known application even if it is absolutely unique. Well, the domain is expiring, the site is hosted thanks to a friend of mine, the MyMin project in Python, PHP, C#, JavaScript, will be probably moved in Google Code if and when I will have time. Right now it is not even working with FireFox, just IE7 and few other browsers ... the reason? No time to update it, and low interests from Web community. So what's next? I have no idea, but if you are interested, packed.it domain is gonna be free soon, and my service is gonna be down soon as well. Thanks to those developers who believed in packed.it and used it for some project :)

Multiple Upload With Progress: Every Browser No Flash !!!

Image
Update: released official version in Google Code, cross browser, and easy to use. blog enry Ok guys, this is a quick and dirty entry in my blog. I need to write documentation, create the project in Google Code, explain better what I have done and how it works. I do not want to give you the zip right now because I have to change name (silly me do not check before) and to do last tests ... but basically, what I have created this week end, is a graceful enhanced multiple file upload manager compatible with Chrome, FireFox, Internet Explorer (5.5 or greater), Opera, Safari. The manager wrap an input type file and manages it allowing multiple files selection, where supported, or one after one insert with possibility to remove one or more file from the list. Everything is absolutely customizable, since the wrapper is entirely in CSS, the library has a language namespace for errors or messages, and events are created by developers. In those browsers were Ajax upload is not supported, the pro...

Safari 4 Multiple Upload With Progress Bar

Update - I slightly modified the demo page adding another bar, the one for the current file. I'll update the zip asap but all you need is a copy and paste of the JS in the index. Apparently multiple should be set as multiple, rather than true ... in any ... it works as long as it is an attribute. This one from Ajaxian has been one of the best news I could read about HTML5 specs and browsers evolution. I could not wait to download Safari 4 and test instantly this feature. I have always been interested in this possibility, both progress bar, plus multiple uploads and that's why I would like to add this post to this list: PHP upload progress , 22 September 2005 FileReference for JavaScript , 08 November 2005 Upload progress bar with PHP5, APC and jQuery , 09 October 2007 First Step: The Input Type File We can create a multiple input files in different ways: directly in the layout <input type="file" multiple="multiple" /> or via JavaScript:...

PHP to Jaxer Server And Vice-Versa

Basis If we have a configuration Jaxer + PHP, as is as example in my pampa-j project , we should know that these two languages cannot directly interact as is, for example, with Jaxer and Java. The interpreted and executed order is this one: the PHP module parses the request and the page before Jaxer module after PHP has finished its stuff, the Jaxer Server module parses the page which could has been modified during PHP execution after the Jaxer Server has finished its stuff, the user receives the generated page Above order means that we can pass variables to Jaxer but we cannot pass back results to PHP <?php // simple variable from PHP to Jaxer $myVar = 'Hello World'; echo '<script runat="server"> myPHPVar = '.json_encode($myVar).'; onload = function(){ // will show Hello World document.body.innerHTML = myPHPVar; }; </script>'; ?> As summary, if we print out a script tag wth a valid JavaScript for server, c...