Page 1 of 1

lost functions....

Posted: Mon May 21, 2007 11:51 pm
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]

Posted: Tue May 22, 2007 12:00 am
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');