localhost Posted September 6, 2006 Share Posted September 6, 2006 class_core.php[code=php:0]class Omega { var $Omega; function Omega() { function Query($Query) { $Result = @mysql_query($Query); if (!$Result) { echo mysql_error(); return false; } else { return $Result; } } function FetchArray($SelectQuery) { $Result = @mysql_fetch_array($SelectQuery); if (!$Result) { echo mysql_error(); return false; } else { return $Result; } } function NumRows($Query) { $Result = @mysql_num_rows($Query); if (!$Result) { echo mysql_error(); return false; } else { return $Result; } } function Input($PostInput) { $Output = mysql_real_escape_string(htmlentities($PostInput)); if (!empty($PostInput)) { return $Output; } else { echo 'OmegaInput(): Invalid or no string specified.'; exit(); } } } }?>[/code]text.php[code=php:0]<?phprequire('include/class_core.php');$Omega = new Omega();$text = $Omega->Input($_POST['text']);echo $text;?><form action="<?php $PHP_SELF; ?>" method="post">texT:<input type="text" name="text" /></form>[/code]I get the error:Fatal error: Call to undefined function: input()I want to be able to use that clsas core file and have $Omega->Function functions....any ideas? i know it can be done i just forget how :P Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/ Share on other sites More sharing options...
trq Posted September 6, 2006 Share Posted September 6, 2006 The code you have posted should work. The error you post howver refers to a function called input() NOT Input(). Are you sure this is the relevent coe?ps: Whatever editor your using to copy / paste this code... get rid of it. Your formatting is near impossible to read. Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/#findComment-86909 Share on other sites More sharing options...
localhost Posted September 6, 2006 Author Share Posted September 6, 2006 that is the exact code and i still get the error for input(). Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/#findComment-86913 Share on other sites More sharing options...
wildteen88 Posted September 6, 2006 Share Posted September 6, 2006 You dont close the constructor (Omega function) in your class:[code]function Omega(){} // <-- missing closing brace.[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/#findComment-86985 Share on other sites More sharing options...
Barand Posted September 6, 2006 Share Posted September 6, 2006 Is nesting of function definitions now permitted? I thought it was a no-no in PHP.Or am I reading that mess of code incorrectly? Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/#findComment-86992 Share on other sites More sharing options...
wildteen88 Posted September 6, 2006 Share Posted September 6, 2006 [quote author=Barand link=topic=107057.msg429082#msg429082 date=1157538819]Is nesting of function definitions now permitted? I thought it was a no-no in PHP.Or am I reading that mess of code incorrectly?[/quote]You've always been able to nest functions in PHP AFAIK. To call nested function you first have to call the function that is containing the nested functiont first, then you can call the nested function. Example:[code=php:0]function foo(){ echo 'foo<br />'; function bar() { echo 'bar'; }}// call parent functionfoo();// now call nested functionbar();[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/#findComment-86993 Share on other sites More sharing options...
Barand Posted September 6, 2006 Share Posted September 6, 2006 I'm sure I tried to do something like this a long time ago and it failed.[code]<?phpfunction foo(){ function bar() { echo 'bar'; } echo 'foo<br />'; bar();}foo();?>[/code]Guess I had something else wrong and made wrong assumption.Thanks for that Wildteen Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/#findComment-86996 Share on other sites More sharing options...
Barand Posted September 6, 2006 Share Posted September 6, 2006 try[code]<?phpclass Omega { var $Omega; function Omega() { // constructor $this->Omega = 0; //initialise variables } function Query($Query) { $Result = @mysql_query($Query); if (!$Result) { echo mysql_error(); return false; } else { return $Result; } } function FetchArray($SelectQuery) { $Result = @mysql_fetch_array($SelectQuery); if (!$Result) { echo mysql_error(); return false; } else { return $Result; } } function NumRows($Query) { $Result = @mysql_num_rows($Query); if (!$Result) { echo mysql_error(); return false; } else { return $Result; } } function Input($PostInput) { if (!empty($PostInput)) { $Output = mysql_real_escape_string(htmlentities($PostInput)); return $Output; } else { echo 'OmegaInput(): Invalid or no string specified.'; exit(); } }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19859-classes/#findComment-87005 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.