loganbest Posted September 6, 2007 Share Posted September 6, 2007 How is the best way to BackPort OOP PHP 5 to PHP 4.4.7? Quote Link to comment Share on other sites More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 I would think you'll need to manually go through the code and change what is required. Be aware though that there is quite alot more functionality available to php5, some of which will be very difficult to near impossible to backport. Quote Link to comment Share on other sites More sharing options...
loganbest Posted September 6, 2007 Author Share Posted September 6, 2007 I have no idea how to backport in the firstplace. I just learned a little bit of OOP but accidentally learned it through php 5, unfortunately my server has php 4.4.7 and I don't have the time to relearn or upgrade the server and risking my site breaking then having to recode 25,000 lines of code. Quote Link to comment Share on other sites More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 If you just learnt a little bit of OOP then its highly likely your not using the more advanced features included in php5. The biggest simple differences between 4 and 5 are that 4 does not support visability declerations. So, where you would declare a property in php5 using... public $varname; you simply use... var $varname; in php4. Of course this also meens there is no such thing as private or protected properties in php4. php4 also does not support the __construct() method in the same way as php5. In php4 your construct function uses the same name as the class instead of __construct() used in php5. eg; <?php class foo { function foo() { echo "this is a php4 construct"; } } ?> There the basics, but there is alot more to it. Just depends how complex your php5 OOP is I suppose. Quote Link to comment Share on other sites More sharing options...
corbin Posted September 6, 2007 Share Posted September 6, 2007 You could probably get a lot of it just with some basic replacement or regular expressions.... For example, you could just replace 'plublic $' with 'var $'. Or, if you wanted to be more fancy you could do it with regular expressions: /(public|private) \$/ -> var $ Quote Link to comment Share on other sites More sharing options...
loganbest Posted September 6, 2007 Author Share Posted September 6, 2007 ok I made the __contruct() function reflect the class name as video(). Now how would the public/var replacement work with this. keep in mind this is my original unchanged script. <?php //video class class Video { var $uploaddir; var $localdir; var $vidName; var $vidFileDir; var $thumbnail_name; var $thumbnail_width = 150; var $thumbnail_height = 150; var $thumbnail_dir; var $thumbnail_img; var $thumbnail_localdir; public function __get($var) { return $this->{$var}; } public function __set($var, $val) { $this->{$var} = $val; } public function version() { $ver = "<!--\n"; $ver .= "Video Test Script\n"; $ver .= "requires: \n"; $ver .= "-Flash Video Player ( http://www.jeroenwijering.com/?item=Flash_Video_Player )\n"; $ver .= "-ffmpeg (http://ffmpeg.mplayerhq.hu/ )\n"; $ver .= "-PHP4.4.7 or later"; $ver .= "\n\nAuthor: Logan Best\n-->\n"; return $ver; } public function __construct($width = 320, $height = 260, $bgColor = "#eaeaea") { echo $this->version(); echo "<script language=\"javascript\" src=\"js/ufo.js\"></script>\n"; echo "<script language=\"javascript\">\n function playMovie(file)\n{\nvar FO = \n{\nmovie:\"flvplayer.swf\",\nwidth:\"".$width."px\",\nheight:\"".$height."px\",\nmajorversion:\"7\",\nbuild:\"0\",\nbgcolor:\"#eaeaea\",\nflashvars:\"file=\"+file+\"&autoStart=true\"\n};\n UFO.create(FO, 'player');\n}\n </script>\n"; }//__construct var function upload() { $files = $_FILES; /* echo '<pre>'; var_dump($_FILES); echo '</pre>'; */ if($this->uploaddir == '') { if(!file_exists('videos/')) { mkdir('videos/'); //echo 'making dir'; }//if $this->uploaddir = 'videos/'; }//if @$uploadfile = $this->uploaddir . basename($files['file']['name']); $this->vidFileDir = $uploadfile; if(@move_uploaded_file($files['file']['tmp_name'], $uploadfile)) { $noExt = explode(".", $files['file']['name']); $name = $noExt[0]; if($noExt[1] == "wmv") { exec("mencoder ". $this->uploaddir . $files['file']['name'] . " " . $this->uploaddir . $name . ".flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=400:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -srate 22050"); exec("flvtool2 -Uv " . $this->uploaddir . $name . ".flv " . $this->uploaddir . $name . ".flv"); $veed = $this->localdir . $name . ".flv"; //$this->vidFileDir = $veed; $this->vidName = $name . "flv"; } else { exec("ffmpeg -i " . $this->uploaddir . $files['file']['name'] . " " . $this->uploaddir . $name . ".flv"); $veed = $this->localdir . $name . ".flv"; //$this->vidFileDir = $veed; $this->vidName = $name . "flv"; } if(isset($this->thumbnail_name)) { $this->thumbnail(); } return $veed; } else { die("UPLOAD FAILED"); }//if/else }//uploadVideo //$file must be a full path -- $thumbdir is where to store the thumbnails public function thumbnail() { $flvFileDir = explode(".",$this->vidFileDir); $flvFile = $flvFileDir[0] . ".flv"; $file = $this->thumbnail_name; $width = $this->thumbnail_width; $height = $this->thumbnail_height; $dir = $this->thumbnail_dir; if(isset($this->thumbnail_dir)) { $thumbName = $dir . $file . ".jpg"; //die($flvFile . "<br>" . $thumbName); exec("ffmpeg -y -i " . $flvFile . " -f mjpeg -ss 10 -vframes 1 -s " .$width."x".$height." -an " . $thumbName); $this->thumbnail_img = $this->thumbnail_localdir . $file . ".jpg"; } else { die("Thumbnail failed: no thumbnail dir set"); } }//thumbnail public function delVideo($file) { //$file must be full path if(file_exists($file)) { unlink($file); return true; } else { $res = "This file does not exist."; return $res; }//if/else }//delVideo public function player($veed = '') { if($veed == '') { echo "Video source has not been supplied"; } else { if(!file_exists($veed)) echo "Video file does not exist"; else echo "<script language=\"javascript\">playMovie('".$veed."');</script>"; }//if }//player }//Video Quote Link to comment Share on other sites More sharing options...
corbin Posted September 6, 2007 Share Posted September 6, 2007 public function Would just need to be function And as for the var public function, I'm not sure if that's even valid in PHP5.... Quote Link to comment Share on other sites More sharing options...
loganbest Posted September 6, 2007 Author Share Posted September 6, 2007 oops I think the var function was a typo for public function Quote Link to comment Share on other sites More sharing options...
trq Posted September 6, 2007 Share Posted September 6, 2007 Also the __get and __set features (overloading) do not exist within php4. Its starting to look pretty safe to assume that your going to need a complete rewrite. Either that or find a host that supports php5. Hell, I don't think php6 is too far off a release. Quote Link to comment Share on other sites More sharing options...
loganbest Posted September 6, 2007 Author Share Posted September 6, 2007 well after doing the public delete and __construct() -> video() replacement, I actually see the page and not a parse error. How would I rewrite the __get and __set features to work? and anything else that might need rewriting Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 6, 2007 Share Posted September 6, 2007 Logan... Just get your host to mke php5 available - many hosts have 4 and 5 engines installed and allow you to select which one in your control panel - if your hosts don't then ask them what you are paying for!!!!!! Quote Link to comment Share on other sites More sharing options...
448191 Posted September 6, 2007 Share Posted September 6, 2007 I'll agree with that. I don't use stick to make fire either. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted September 6, 2007 Share Posted September 6, 2007 __get and __set (as well as __call) will work, but you need to use the overload() function before you instantiate the class. When i've used it in the past, I've just thrown it at the bottom of the class file so it gets called by default - so if my class is called - erm - MyClass, then just: <?php class MyClass { ... code ... } overload('MyClass'); ?> will do the trick. there's an example here Quote Link to comment Share on other sites More sharing options...
loganbest Posted September 12, 2007 Author Share Posted September 12, 2007 Logan... Just get your host to mke php5 available - many hosts have 4 and 5 engines installed and allow you to select which one in your control panel - if your hosts don't then ask them what you are paying for!!!!!! I own a dedicated self managed server. I'd love to upgrade to PHP 5 but i've coded all 25,000 lines of my site to work with 4 and I just don't have the time to completely recode it all for 5. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted September 12, 2007 Share Posted September 12, 2007 I own a dedicated self managed server. I'd love to upgrade to PHP 5 but i've coded all 25,000 lines of my site to work with 4 and I just don't have the time to completely recode it all for 5. you won't have to. PHP5 is probably 99.9% backward compatible with PHP4. I moved to a PHP5 server taking about 5 sites and approx 10 staging environments with it, taking only about 30 mins to 'tweak' the lot, and mostly were changing php.ini settings to how I like them where they differ from defaults. It'll take you much less time to upgrade the server than it will to backport. And if the code is already working with PHP4, where's the issue? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.