Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP - Driving me Loopy! Pls Help!

Featured Replies

Ok I have a class in the format of:

 

class Code{
....

function getName(){
$val = 'Test';
return $val;
}

function getOtherName(){
$val = 'Test';
return $val;
}

}

 

Then I use this class on another page like this:

 

$code = new Code();
$value = $code->getName();

Which works fine, but when I add:

$anotherval = $code->getOtherName();

underneath it comes up with this error:

Call to a member function on a non-object in /var/www/.../code.php on line 3

 

I mean why?! I use classes all the time, what's so abnormal about this?

What am I missing?! It's got to be something so stupid!

  • Author

And to confuse matters even more confusing if I do:

 

$code = new Code();
$anotherval = $code->getOtherName();
$value = $code->getName();

 

It seems to work fine!

Have I been missing a basic rule of PHP all these years or something?

Nothing wrong with that, works for me. There must be more to it, can you paste your entire code?

  • Author

code.php

$code = new Code();
$code->retrieveCodeInfo($codeid);
$ven	= $code->venue();
$id		= ' ';
$name	= $code->getCourseName();

 

code.inc.php

require_once("database.inc.php");

class Code {	
var $codeid;
var $loc;
var $courseid;
var $code;
var $occur;
var $sdate;
var $edate;
var $hrswk;
var $numwks;
var $daytime;
var $tutor;
var $active;
var $vp;
var $drop;

function retrieveCodeInfo($id){
	$this->codeid = $id;

	$sql = "SELECT * FROM Course WHERE id = '$this->codeid'";
	$dbconn = new Database();
	$result = $dbconn->getQueryResults($sql);
	$row = mysql_fetch_array($result);

	$this->loc		= $row['Location_code'];
	$this->courseid		= $row['course_id'];
	$this->code			= $row['code'];
	$this->occur		= $row['occur'];
	$this->sdate		= $row['start_date'];
	$this->edate		= $row['end_date'];
	$this->hrswk		= $row['hours_week'];
	$this->numwks		= $row['num_weeks'];
	$this->daytime		= $row['day_times'];
	$this->tutor		= $row['tutor'];
	$this->active		= $row['active'];
	$this->vp			= $row['vp_validated'];
	$this->drop			= $row['dropin'];
}

function getCourse(){
	$val = 'Test';

	return $val;
}

function getCourseName(){
	$tip = 'Test';

	return $tip;
}

function getCode($mode='edit'){
	if($mode == 'edit'){
		$val	=	'<input name="code" type="text" value="'.$this->code.'" />';
	}else{
		$val	=	$this->code;
	}
	return $val;
}

function venue(){
	$val = 'please work';
	return $val;
}
}

  • Author

Its in code.php

$code = new Code();
$code->retrieveCodeInfo($codeid);
$ven	= $code->venue();
$id		= ' ';
$name	= $code->getCourseName();

The problem happens when i put $ven underneath $name

  • Author

Would Server settings have any effect to this? We had a power cut last night and our server restarted. That wouldn't be causing this strange behavoir would it?

  • Author

When I put in:

error_reporting(E_ALL);

 

Still just comes up with:

Fatal error: Call to a member function on a non-object in

 

Thanks for your thoughts, i do appreciate it...

  • Author

print_r( $code );

Doesn't pull back anything when the error is showing, but when i put it the way that will display it properly (by reordering the lines again) it just displayed the value that is pulled from the database.

 

Would any server settings what so ever have an effect on this? Because I really confuzzled...

Not that I can think of. Why would rebooting a server cause its settings to change?

What version of PHP do you have?

 

If you haven't got the latest then try updating if possible incase it's some random PHP bug.

  • 2 weeks later...

Hey man

 

Try testing it under different environments. I replicated your code and it works fine for me.

 

Interesting problem though

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.