myrddinwylt Posted July 6, 2010 Share Posted July 6, 2010 Hello, I decided to give php 5.3.2 another go: Got it working for the most part if I don't care about 100 of the 130 extensions available. Strange problem: $v = new test(); echo $v->testfunction(); class test() { function testfunction() { return "hello"; } } Any reason why the above code doesn't work on PHP 5.3.2 ? Did something change with the way classes are declared ? I have also tried: $v = new test; echo $v->testfunction(); class test { function testfunction() { return "hello"; } } By all rights and logic, this code should output "hello" to the browser, but instead nothing happens. I first noticed this problem with a much more complex class include which I have made regarding the creation of openssl certificates and such, and managed to break the problem down to the above -- it's simplest form. Please note that all of my classes work without error under PHP 5.2.8. Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2010 Share Posted July 6, 2010 Show us the opening php tag you are using in the file. Edit: And the first code contains a fatal parse error (there are no () after the class name in the declaration.) So, you should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php would report and display all the errors it detects. Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082104 Share on other sites More sharing options...
myrddinwylt Posted July 6, 2010 Author Share Posted July 6, 2010 Hello, Opening and closing PHP tags are as follows: <?php The PHP code is in here ?> Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082111 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2010 Share Posted July 6, 2010 Under php 5.3.2 your first code produces a fatal parse error due to the incorrect syntax (which is incorrect in all php4/5 versions) and your second code works as expected. Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082114 Share on other sites More sharing options...
myrddinwylt Posted July 6, 2010 Author Share Posted July 6, 2010 The more complicated code in question is as follows: config.inc.php <?php $webserver["path"] = "c:/server/websites"; // Path without trailing slash $webserver["theme"] = "basic"; // Choose the webserver admin template $webserver["wysiwyg"] = "false"; // Default mode for editing html files (true = WYSIWYG on) $webserver["statspath"] = "C:/Program Files (x86)/AWStats/wwwroot/cgi-bin"; $webserver["editfiles"] = "conf,js,txt,sql,php,html,htm,pl,cgi,css,tpl,log,htpasswd,htaccess"; // Editable file types $dns['enabled'] = false; // Enable SimpleDNS server support (true/false) $dns['server'] = "127.0.0.1"; // SimpleDNS Server $dns['user'] = ""; // SimpleDNS Username $dns['pass'] = ""; // SimpleDNS Password $dns['port'] = 53; // SimpleDNS Port $filetypes['ext'] = split(",","bmp,dll,doc,exe,gif,hlp,html,ini,java,jpg,list,mpg,pdf,php,pps,ppt,reg,ttf,txt,xls,zip"); // Supported file types $mail['enabled'] = false; // Enable Merak Mail server support (true/false) $mail['path'] = "c:/program files/merak"; // Set to Merak Mail server path include("classes/template.php"); $template = new template($webserver["path"],$webserver["theme"]); ?> viewcsr.php <? if(!isset($webserver["path"])){ include("config.inc.php"); } if($_POST["submit_x"]) { $domain = $_POST["domain"]; $csr = file_get_contents($webserver["path"]."/".$domain."/certs/certificate.csr"); $data = $template->read("viewcsr2","Certificate Request for ".$domain); $data = str_replace("#domain#",$domain,$data); $data = str_replace("#csr#",$csr,$data); print $data; } else { $fields = ""; if (is_dir($webserver["path"])) { if ($dh = opendir($webserver["path"])) { while (($file = readdir($dh)) !== false) { if (is_dir($webserver["path"] ."/". $file)) { switch ($file) { case ".": break; case "..": break; default: if($file != "127.0.0.1") { if(file_exists($webserver["path"]."/".$file."/certs/certificate.csr")) { $fields .= "<p> <input id=\"domain\" type=\"radio\" name=\"domain\" value=\"".$file."\"> ".$file."</p>"; } } break; } } } closedir($dh); } } if($fields == "") { $data = $template->read("viewcsr-blank","View Certificate Requests"); } else { $data = $template->read("viewcsr","View Certificate Requests",""); $data = str_replace("#FIELDS#",$fields,$data); } print $data; } ?> template.class.php <?php class template { var $path = ""; var $theme = ""; public function __construct($path, $theme) { $this->path = $path; $this->theme = $theme; } function readfull($name,$title='',$body='') { $info = file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/".$name.".html"); if($title==''){ $title = "Web Server Pro"; } else { $title = "Web Server Pro :: ".$title; } $info = str_replace("#TITLE#",$title,$info); if($body!=''){ $info = str_replace("#BODY#",$body,$info); } return $info; } function read($name,$title='',$body='',$header='',$fields='') { $info = file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/header.html"); if($title==''){ $title = "Web Server Pro"; } else { $title = "Web Server Pro :: ".$title; } $info = str_replace("#TITLE#",$title,$info); $info = str_replace("#HEADER#",$header,$info); $info .= file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/".$name.".html"); if($body!=''){ $info .= $body; } if($fields!=''){ $info = str_replace("#FIELDS#",$fields,$info); } $info .= file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/footer.html"); return $info; } function status($name,$scriptname='',$timer=0,$title='',$message='',$secondtemplate='') { $info = file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/header.html"); if($title==''){ $title = "Web Server Pro"; } else { $title = "Web Server Pro :: ".$title; } $info = str_replace("#TITLE#",$title,$info); if($timer>0) { $info = str_replace("#HEADER#","<meta http-equiv='refresh' content='".$timer."; url=".$scriptname."'>",$info); } else { $info = str_replace("#HEADER#","",$info); } $info .= file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/".$name.".html"); $info = str_replace("#MESSAGE",$message,$info); if($secondtemplate) { $info .= file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/".$secondtemplate.".html"); } $info .= file_get_contents($this->path."/127.0.0.1/htdocs/templates/".$this->theme."/footer.html"); return $info; } } ?> openssl.class.php <?php class openssl { var $path = ""; var $pathopenssl = ""; var $privatekey = ""; var $publickey = ""; var $csr = ""; var $domain = ""; var $certificate = ""; // public function __construct($path, $domain, $private='', $public='', $csr='', $signed='') { public function __construct($path, $domain) { $this->path = $path; $this->pathopenssl = str_replace("/websites","/bin/openssl.cfg",$path); $this->domain = $domain; } function save() { file_put_contents($this->path."/".$this->domain."/certs/certificate.key",$this->privatekey); file_put_contents($this->path."/".$this->domain."/certs/certificate.csr",$this->csr); if($this->publickey) { file_put_contents($this->path."/".$this->domain."/certs/certificate.pub",$this->publickey); } if($this->certificate) { file_put_contents($this->path."/".$this->domain."/certs/certificate.crt",$this->certificate); } } function save_public() { file_put_contents($this->path."/".$this->domain."/certs/certificate.pub",$this->publickey); } function save_private() { file_put_contents($this->path."/".$this->domain."/certs/certificate.key",$this->privatekey); } function save_signed() { file_put_contents($this->path."/".$this->domain."/certs/certificate.crt",$this->signed); } function save_csr() { file_put_contents($this->path."/".$this->domain."/certs/certificate.csr",$this->csr); } function save_cert($certificate) { file_put_contents($this->path."/".$this->domain."/certs/certificate.crt",$this->certificate); } function getprivatekey($password='') { $key = openssl_get_privatekey($private,$password); openssl_private_decrypt($key,$newsource,$res); } function generate_csr($country='CA',$state='Ontario',$locality='Oshawa',$organization='Organization',$organizationunit='IT Department',$domain='127.0.0.1',$email='[email protected]') { $dn = array( "countryName" => $country, "stateOrProvinceName" => $state, "localityName" => $locality, "organizationName" => $organization, "organizationalUnitName" => $organizationunit, "commonName" => $domain, "emailAddress" => $email ); $config = array("config"=>$this->pathopenssl); $privkey = openssl_pkey_new($config); openssl_pkey_export($privkey, $private, null, $config); $csrnew = openssl_csr_new($dn, $privkey, $config); openssl_csr_export($csrnew, $csr); // while ($msg = openssl_error_string()) // echo $msg . "<br />\n"; // var_dump(openssl_pkey_get_private(array($private,""))); $this->privatekey = $private; $this->csr = $csr; $keys = array("private"=>$private, "csr"=>$csr); return $keys; } function generate_signed($country='CA',$state='Ontario',$locality='Oshawa',$organization='Organization',$organizationunit='IT Department',$domain='127.0.0.1',$email='[email protected]', $days=365) { $dn = array( "countryName" => $country, "stateOrProvinceName" => $state, "localityName" => $locality, "organizationName" => $organization, "organizationalUnitName" => $organizationunit, "commonName" => $domain, "emailAddress" => $email ); $config = array("config"=>$this->pathopenssl); $privkey = openssl_pkey_new($config); $csrnew = openssl_csr_new($dn, $privkey, $config); $sscert = openssl_csr_sign($csrnew, null, $privkey, $days, $config); openssl_x509_export($sscert, $certificate); $pubkey = openssl_pkey_get_public($certificate); $public = openssl_pkey_get_details($pubkey); openssl_pkey_export($privkey, $private, null, $config); openssl_csr_export($csrnew, $csr); $this->certificate = $certificate; $this->privatekey = $private; $this->publickey = $public["key"]; $this->csr = $csr; $keys = array("private"=>$private, "csr"=>$csr, "certificate"=>$certificate,"public"=>$public["key"]); return $keys; } } ?> When browsing to viewcsr.php it should be displaying a form, but instead, it's going really wonky and displaying the following: read("viewcsr2","Certificate Request for ".$domain); $data = str_replace("#domain#",$domain,$data); $data = str_replace("#csr#",$csr,$data); print $data; } else { $fields = ""; if (is_dir($webserver["path"])) { if ($dh = opendir($webserver["path"])) { while (($file = readdir($dh)) !== false) { if (is_dir($webserver["path"] ."/". $file)) { switch ($file) { case ".": break; case "..": break; default: if($file != "127.0.0.1") { if(file_exists($webserver["path"]."/".$file."/certs/certificate.csr")) { $fields .= " ".$file." "; } } break; } } } closedir($dh); } } if($fields == "") { $data = $template->read("viewcsr-blank","View Certificate Requests"); } else { $data = $template->read("viewcsr","View Certificate Requests",""); $data = str_replace("#FIELDS#",$fields,$data); } print $data; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082117 Share on other sites More sharing options...
myrddinwylt Posted July 6, 2010 Author Share Posted July 6, 2010 I think I just realized the problem as you correctly inquired into. In some of my classes I got lazy and was using the short code to open PHP with <? instead of <?php . Where is this set again in the php.ini. It has literally been 2 years since I mucked about in it, and now I have a 70kb ini, instead of my 30kb ini, because of the insanity of comments XD. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082118 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2010 Share Posted July 6, 2010 You got caught using one of php's blunders, the lazy-way short open tag <? Use full php tags <?php so that your php code will always be seen as php code. And if you actually state what problem you are having and what the code is that experiences that problem, you can get quicker solutions to your problems. Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082119 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2010 Share Posted July 6, 2010 It will only take a couple of minutes using a programming editor to globally search/replace <? with <?php in all your files. I recommend these steps - 1) Replace <? with <?php 2) Replace <?phpphp with <?php 3) Replace <?php= with <?php echo Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082120 Share on other sites More sharing options...
myrddinwylt Posted July 6, 2010 Author Share Posted July 6, 2010 Thankfully, I have never done <?phpphp Nor would I ever use <?php= The shortcode i did <? Was more the result of 38 hours of programming with no sleep, so I got a bit lazy on a couple of my opening tags, since I enabled the support in the php.ini file to allow for that (you would be suprised at how many commercial and open source projects use the short tag... which is why I enabled the support in the first place --- doing a search & replace in all files for "<?" would result in "<?phpphp" as you stated above. Much easier to simply enable short codes, and since ASP is something that will never work on php ..... "<?" and "<%" should work just peachy if enabled. Now im gonna have to read that whole php.ini file again to locate where the hell short-code support is, as I need to re-enable it for 3rd party app support. (Ridiculous, but some apps that are encoded with IONCUBE, like to use short-codes in the encrypted code, or protected areas). Cheers, and thanks again Quote Link to comment https://forums.phpfreaks.com/topic/206928-are-classs-broken-in-php-532-stable/#findComment-1082176 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.