6 Replies - 12896 Views - Last Post: 19 April 2007 - 04:00 PM Rate Topic: -----

#1 max302  Icon User is offline

  • Proud supporter of the lulz
  • member icon

Reputation: 2
  • View blog
  • Posts: 1,281
  • Joined: 05-March 06

Class definition and variables

Posted 17 April 2007 - 11:39 AM

Something is going wrong with my class declarations. This is my first try at OO PHP, and according to the docs, im doing this right. I'm getting error message :

Quote

Parse error: syntax error, unexpected T_VARIABLE in D:\site_back_20061113\sites\max\maximerousseau.com\netorganizer\index.php on line 22

<?PHP


//	Modes
// Default -- Starts with no GET args, displays empty interface
//			   Domain Name is kept in a POST variable re-feed
// Edit -- Edits a machine or group info in regular form by over
//		 writing the info in the array.

// Global variable declaring number of groups and machines per group

$GLOBALS['num_groups'] = 1;

// Symbolic declaration of array $groups and $machines

$groups;
$machines;

// Class Declarations	
	class group
	{
	$upper_range = $_POST['g_upper_range'];
	$lower_range = $_POST['g_lower_range'];
	$name = $_POST['g_name'];
	$num_machines = 0;
	$index = $GLOBALS['num_groups'];
	$GLOBALS['num_groups']++;
	$num_machines = 0;
	}
	
	class machine
	{
	$name = $_POST['m_name'];
	$mac[1] = $_POST['m_mac1'];
	$mac[2] = $_POST['m_mac2'];
	$mac[3] = $_POST['m_mac3'];
	$mac[4] = $_POST['m_mac4'];
	$mac[5] = $_POST['m_mac5'];
	$mac[6] = $_POST['m_mac6'];
	$group = $_POST['m_group'];
	$index = parent::$groups[$group]::num_machines + 1;
	parent::$groups[$group]::num_machines++;
	}

//	PARSE ALL $_POST VARS!

//	Intranet Settings
if (isset($_POST['domain']))
 	{$domain = $_POST['domain'];}
if (isset($_POST['thirdnum']))
	{$thirdnum = $_POST['thirdnum'];}

// 	Parse Group information
if (isset($_POST['g_name']) && isset($_POST['g_lower_range']) && isset($_POST['g_higher_range']) && isset($_POST['g_index']))
{

}
?>

<html>
 <head>
  <title>Network Organizer Sheet Generator</title>
  <meta content="author" value="Maxime Rousseau">

 </head>

 <body>
  <div class="container">
   <center><h2>Network Organizer Sheet Generator</h2></center> <br />
   <form method="POST" action="index.php">

	<div class="basic">	
	 <h3>Basic Information</h3>
	 <table>
	  <tr>
	 <td><b>Domain Name:</b></td>
	 <td><input type="text" name="domain" <?PHP if (isset($domain)) {echo "value='".$domain."'";} ?> />
	 <td><b>3rd Internal IP Number:</b></td>
	 <td>192.168.<input type="text" name="thirdnum" maxlength="3" size="3" <?PHP if (isset($thirdnum)) {echo "value='".$thirdnum."'";} ?> />.1</td>
	</tr>
	 </table>
	</div>
	
	<div class="group">
	 <h3>Add a Group</h3>
	 <table>
	  <tr>
	 <td><b>Name:</b></td>
	 <td><input type="text" name="g_name" /></td>
	 <td><b>Range:</b>
	 <td><input type="text" name="g_lower_range" maxlength="3" size="3" /> - <input type="text" name="g_higher_range" maxlength="3" size="3" /></td>
	</tr>
	<tr>
	 <td><b>Index:</b></td>
	 <td><input type="text" name="g_index" maxlength="2" size="2" /></td>
	 <td colspan="2"><input type="submit" value="Add Group" />
	</tr>
	 </table>
	</div>

	<div class="machine">
	<h3>Add a Machine</h3>
	 <table>
	  <tr>
	 <td><b>Name:</b></td>
	 <td><input type="text" name="m_name" maxlength="30" size="3" /></td>
	 <td><b>MAC Address:</b></td>
	 <td>
		<input type="text" name="m_mac1" size="2" maxlength="2" />:
		<input type="text" name="m_mac2" size="2" maxlength="2" />:
		<input type="text" name="m_mac3" size="2" maxlength="2" />:
		<input type="text" name="m_mac4" size="2" maxlength="2" />:
		<input type="text" name="m_mac5" size="2" maxlength="2" />:
		<input type="text" name="m_mac6" size="2" maxlength="2" />:	
	</td>
	 <td><b>Group Index:</b></td>
	 <td>
	  <select name="m_gindex">
	   <?PHP
		$m_gindexc
		while (isset(groups[$m_gindexc]))
		{
		echo "<option value='".$groups[$m_gindexc]::index"'>".$groups[$m_gindexc]::name."<value>";
		}
	   ?>
	  </select>
	 </td>
	</tr>
	<tr>
	 <td colspan="2"><b>Number of Services:</b></td>
	 <td colspan="4"><input type="text" name="m_num_services" size="2" maxlength="2" /></td>
	</tr>
	  <?PHP
	 //#INSERT SERVICE LOOP HERE# 
	?>
	 </table>
	</div>
   </form>
  </div>
 </body>
</html>		


Is This A Good Question/Topic? 0
  • +

Replies To: Class definition and variables

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Class definition and variables

Posted 17 April 2007 - 07:59 PM

You need to have var, public, protected, or private before those property declarations.

class group
	{
	$upper_range = $_POST['g_upper_range']; //THIS IS WRONG!!!!!
	var $lower_range = $_POST['g_lower_range']; //PHP 4 or older way.
	public $name = $_POST['g_name']; //PHP 5 only and it's way of doing var...var can still be used.
	protected $num_machines = 0; //PHP 5 only
	private $index = $GLOBALS['num_groups']; //PHP 5 only
	var $GLOBALS['num_groups']++;
	var $num_machines = 0;
	}


You can find out more about class property visibility here.
Was This Post Helpful? 0
  • +
  • -

#3 max302  Icon User is offline

  • Proud supporter of the lulz
  • member icon

Reputation: 2
  • View blog
  • Posts: 1,281
  • Joined: 05-March 06

Re: Class definition and variables

Posted 18 April 2007 - 10:17 AM

Nope, doesn't work. Here is the fixed code:
// Class Declarations	
	class group
	{
	public $upper_range = $_POST['g_upper_range']; //This is line 22
	public $lower_range = $_POST['g_lower_range'];
	public $name = $_POST['g_name'];
	public $num_machines = 0;
	public $index = $GLOBALS['num_groups'];
	var $GLOBALS['num_groups']++;
	public $num_machines = 0;
	}



Even with the explicit public and var declarations, I still get unexpected T_VARIABLE on line 22, corresponding to the first variable declaration in my class. Stumped.
Was This Post Helpful? 0
  • +
  • -

#4 tundrafiend01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-April 07

Re: Class definition and variables

Posted 18 April 2007 - 10:33 AM

Max:

I have a couple of suggestions for you, unfortunately, I don't have access to a server with php loaded at the moment.

Suggestion 1:

Have you tried the base class definition without the variables? One thing, that I would try, is to comment out all of the variables, ensure no errors are thrown, and then proceed through the list of variables until you find the culprit of your issues.

Suggestion 2:

I'm not familiar with the use of $GLOBALS, nor the rules for such variables, but instead of:


	var $GLOBALS['num_groups']++;
	



try:


	   var $GLOBALS['num_groups'] += 1;




Either way, good luck in your quest to fix your issues.
Was This Post Helpful? 0
  • +
  • -

#5 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Class definition and variables

Posted 18 April 2007 - 10:39 AM

Hmm, I think it's because you're using variables to declare property values.

Try using and __autoload() and __construct() methods to set default values.
Was This Post Helpful? 0
  • +
  • -

#6 max302  Icon User is offline

  • Proud supporter of the lulz
  • member icon

Reputation: 2
  • View blog
  • Posts: 1,281
  • Joined: 05-March 06

Re: Class definition and variables

Posted 19 April 2007 - 03:33 PM

Could an example be supplied? The PHP manual is pretty inaccurate on these two functions.
Was This Post Helpful? 0
  • +
  • -

#7 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Class definition and variables

Posted 19 April 2007 - 04:00 PM

Sorry my bad about __autoload(), it's for including files that hold the class. http://us.php.net/__autoload

__construct() works on the same principle as naming a method after the class. http://us.php.net/ma....oop5.decon.php

Basically, __construct() is called when a used when you create an object. $t = new MyClass();
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1