Jump to content

lesson 5


zeusthegreat

Recommended Posts

index.php

 

 

<?php

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

 

$paths = array(

APPLICATION_PATH,

get_include_path()

 

);

set_include_path(implode(PATH_SEPARATOR, $paths));

function __autoload($className)

{

$filename = str_replace('\\', '/', $className) . '.php';

require_once $filename;

return;

}

 

use \com\killerphp\models as models;

 

 

$User = new models\user();

//echo $User->getName();

 

$User->setAddress("eiffel Tower");

echo $User->XYZgetAddress();

 

 

?>

 

user.php

 

namespace com\killerphp\models;

class User

{

protected $address;

protected $firstName;

protected $lastName;

protected $email;

 

public function setAddress($address)

{

$this->address = $address;

}

 

 

public function __call($name, $args)

 

{

$methodprefix = substr($name, 0, 3);

$methodproperty = substr($name, 4);

echo $methodproperty;

 

}

}

 

?>

 

 

test.php

 

<?php

namespace com\killerphp\controllers;

class test

{

public function __construct()

{

echo "I'm a test class in controllers!";

}

}

 

?>

 

 

and i return etAddress

 

 

and what i should return is ddress

 

 

can not see what i have done wrong, probably something really easy..

 

 

 

 

B):)

 

 

have i got to move xyz

post-32686-040460300 1305025015_thumb.jpg

Edited by talos
Link to comment
Share on other sites

If I understand you correctly... (and, if not, please explain in more detail what you are expecting and what you are actually getting?)

 

you are calling "echo $User->XYZgetAddress();" which calls the "__call()" function:

 

$methodprefix = substr($name, 0, 3);

$methodproperty = substr($name, 4);

echo $methodproperty;

 

Assuming $name is "XYZgetAddress", it sounds like you are getting the correct values. Strings start at position 0 (not position 1), so "0, 3" will give you the first four characters, "X" (at position 0 in the string) through "g" (at position 3.) The second substring should give you characters 4 through the end, so "etAddress".

 

If you are having an issue with this, either you have put the wrong numbers into the substr() functions (perhaps you mean 0, 2 and 3?) or the video author used a four character string rather than your three character "XYZ."

 

Also, just a quick comment... would you mind not adding random image attachments to your posts? They don't have anything to do with the post, and ultimately wasting space/bandwidth on the server. I'm not sure why you are including them in the first place...?

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...