Jump to content

Archived

This topic is now archived and is closed to further replies.

localhost

classes?$

Recommended Posts

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]
<?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>
[/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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You dont close the constructor (Omega function) in your class:
[code]function Omega()
{

} // <-- missing closing brace.[/code]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[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 function
foo();

// now call nested function
bar();[/code]

Share this post


Link to post
Share on other sites
I'm sure I tried to do something like this a long time ago and it failed.
[code]<?php
function 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

Share this post


Link to post
Share on other sites
try
[code]<?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();
        }
    }

}
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.