Jump to content

classes?$


localhost

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.