Jump to content


Photo

Object Oriented PHP


  • Please log in to reply
3 replies to this topic

#1 finisher1017

finisher1017

    New member

  • New Members
  • 3 posts

Posted 27 January 2012 - 03:31 AM

I just started studying object oriented PHP using the begginers tutorial from this site. Using the files below I am having trouble getting the browser to echo the names. I am using an Ubuntu LAMP server with the geany IDE installed and have not had issues with any other pages. Using the same code I was able to get the names to echo successfully on a Windows machine with XAMPP and the Zues IDE installed. I feel like the builds and different IDEs shouldn't matter since I've been able to get all my other pages to work on both machines, so it must be something small I'm overlooking. Any suggestions would be appreciated.


//file used to create class "class_lib.php"
<?php
class person {
var $name;
function set_name($new_name) {
$this->name = $new_name;
}

function get_name() {
return $this->name;
}
}

?>


//file used to retrieve objects and echo data "index.php"
<?php include("class_lib.php"); ?>

</head>
<body>
<?php

$stefan = new person();
$jimmy = new person;

$stefen->set_name("Jonathan Seubert");
$jimmy->set_name("Nick Waddles");

echo "Jonathan's full name: " . $stefan->get_name();
echo "Nick's full name: " . $jimmy->get_name();

?>
</body>
</html>
  • 0

#2 J Stern

J Stern

    Advanced Member

  • Member
  • PipPipPipPip
  • 103 posts

Posted 27 January 2012 - 12:08 PM

I noticed a problem on your lines:

$stefan = new person();
$jimmy = new person;

should be:
$jimmy = new person();

...but I don't see why this would make it work on windows and not linux, the only differences / annoyances I come across between O/S coding is case capitalization's.

Ubuntu server giving you any specific errors?
  • 0

#3 finisher1017

finisher1017

    New member

  • New Members
  • 3 posts

Posted 27 January 2012 - 12:52 PM

I noticed a problem on your lines:

$stefan = new person();
$jimmy = new person;

should be:
$jimmy = new person();

...but I don't see why this would make it work on windows and not linux, the only differences / annoyances I come across between O/S coding is case capitalization's.

Ubuntu server giving you any specific errors?


I noticed that too and tried it with the () in both objects but it still doesn't work on the Ubuntu, even though it works fine in Windows. I'm not getting any errors from Ubuntu, it just won't echo the data from the objects, instead I just get a blank page. It appears that the browser is loading the page, just with no output.
  • 0

#4 finisher1017

finisher1017

    New member

  • New Members
  • 3 posts

Posted 27 January 2012 - 01:39 PM

Never mind. I emptied my localhost folder and recreated the files from scratch and it works on Ubuntu now as well. There must have been some type of conflict with other files in the folder, but its been resolved.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users