Jump to content


Photo

classes?$


  • Please log in to reply
7 replies to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 06 September 2006 - 05:03 AM

class_core.php
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();
												}
											}
										}
									}
?>

text.php
<?php

require('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>

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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 06 September 2006 - 05:39 AM

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.

#3 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 06 September 2006 - 05:46 AM

that is the exact code and i still get the error for input().

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 September 2006 - 10:17 AM

You dont close the constructor (Omega function) in your class:
function Omega()
{

} // <-- missing closing brace.



#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 06 September 2006 - 10:33 AM

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?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 September 2006 - 10:38 AM

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?

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:
function foo()
{
    echo 'foo<br />';

    function bar()
    {
        echo 'bar';
     }
}

// call parent function
foo();

// now call nested function
bar();


#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 06 September 2006 - 10:50 AM

I'm sure I tried to do something like this a long time ago and it failed.
<?php
function foo()
{
    function bar()
    {
        echo 'bar';
     }
    echo 'foo<br />';

    bar();
}

foo();
?>

Guess I had something else wrong and made wrong assumption.

Thanks for that Wildteen
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 06 September 2006 - 11:12 AM

try
<?php
class 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();
        }
    }

}
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users