Accessing Markdown PHP function from within a class

I'm using the Markdown library for PHP by Michel Fortin. Setup is easy and it works great like this:

include_once "markdown.php";
$my_html = Markdown($my_text);

However, I have a class in which I want to pass stuff and 'Markdown' it, like so:

class Test
    public function showMarkdown ($text)
        return Markdown($text);

Obviously, my class is much larger than this, but this is what it boils down to. In my main script I do:

include_once "markdown.php";
$test = new Test();
echo $test->showMarkdown($text);

This returns an error, saying the function 'Markdown' is undefined. That seems obvious, because it's not within the class and I haven't used a scope operator. But when I put the include inside my class and use $this->Markdown or self::Markdown the function is still undefined. I figured that the Markdown function can't be defined inside another function.

So, how can I solve this? I need to do the include, which loads the Markdown function (and the rest of its family) but I want to be able to use it from within my classes. Thanks for your answers/ideas.


Your example code calls a free function called Markdown (which presumably is defined in markdown.php). You simply need to put the include in the same file as your Test class.

After doing this, you will still call Markdown as a free function, and not as an instance ($this->Markdown) or static (self::Markdown) method.

Need Your Help

BorderLayout.NORTH behaving unexpecedly

java swing layout components border-layout

I have a JFrame-descendant window a with a JMenuBar and two components stored in a JPanel. One is a JTabbedPane, which occupies the majority of the screen, and the other is small JPanel that in turn

Running into issues with Django's ModelChoiceField “queryset” attribute

python mysql django django-queryset

In django by default the form for a model foreign key is a ModelChoiceField (where you can select out of a list of all possible models). And it's possible to change these with the query set attribu...