lost functions....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

lost functions....

Post by orbstra »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello! Sorry to bother with such a simple question.. documentation, books, everything's let me down despite I know it is in there..

Code: Select all

class shell{

function loader{
$this->head();
}

function head(){
include (mod.php);
echo $this->mod('head');  //should say theme
}


}
in mod.php

Code: Select all

<?php

function mod($opt){
if($opt=='head'){$return='theme';)
return $return;
}

?>
Whenever I trie to access that function included in that external file I get nothing.... Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

function mod() is not imported to the class' scope (there is no such thing in php) but to the global scope.
You get "nothing" because the script contains numerous errors. Please set error_reporting=E_ALL , display_errors=on and display_startup_errors=on in your php.ini and restart the webserver.

Code: Select all

<?php
function mod($opt){
  if( $opt=='head' ) {
  	$return='theme';
  }
  return $opt;
}

Code: Select all

<?php
class foo {
  function bar(){
    include 'mod.php';
    echo mod('head');
  }
}

$s = new foo;
$s->bar();
echo mod(' tail');
Post Reply