Jump to content

advanced videos lesson two


zeusthegreat

Recommended Posts

index_auto.php

 

<?php

 

define('APPLICATION_PATH', realpath('../'));

$paths = array(

APPLICATION_PATH,

get_include_path()

 

 

 

);

set_include_path(implode(PATH_SEPARATOR, $paths));

 

function _autoload($className)

{

require_once $className .'.php';

return;

}

//var_dump(get_include_path());

//require_once ('user.php');

$User = new User();

echo $User->getName();

 

 

class.php<?php

 

class User

{

public function getName()

{

return "John smith";

}

}

 

?>

 

 

 

methodically went through video and only came across problems towards the end.

 

when i wrote this code and viewed it would not work

 

 

require_once $className .'.php';

return;

 

 

it returns from browser

 

 

Fatal error: Class 'User' not found in C:\wamp\www\coedelobster\video2\index_auto.php on line 19

 

 

 

have no ideas perhaps i have been doing too much and brain scrambled!!!!

post-32686-067517500 1304434147_thumb.jpg

Edited by talos
Link to comment
Share on other sites

what do you mean ben i have tryed below

 

 

 

<?php

define('APPLICATION_PATH', realpath('../'));

 

$paths = array(

APPLICATION_PATH,

get_include_path()

 

);

set_include_path(implode(PATH_SEPARATOR, $paths));

function _"autoload($className)

{

require_once $className . '.php';

return;

}

//var_dump(get_include_path());

//require_once ('user.php');

$User = new User();

echo $User->getName();

 

 

and

 

<?php

define('APPLICATION_PATH', realpath('../'));

 

$paths = array(

APPLICATION_PATH,

get_include_path()

 

);

set_include_path(implode(PATH_SEPARATOR, $paths));

function "_"autoload($className)

{

require_once $className . '.php';

return;

}

//var_dump(get_include_path());

//require_once ('user.php');

$User = new User();

echo $User->getName();

 

 

error

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or '(' in C:\wamp\www\coedelobster\video2\index.php on line 10

 

 

 

just where has it got to go

 

I think the "autoload" function needs two "_" before the function name, not one: http://php.net/manua...5.autoload.php. Try that and see if it fixes things

 

 

have had a look on

http://uk.php.net/autoload

 

and what i have written looks fine, but i am no expert at all

 

thanks for your help ben do not want to go on until i have mastered everything, and i will not let it beat me, done the lesson twice now with exact same result.

post-32686-056052000 1304506764_thumb.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...