473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with class constructor

I am witting a project that needs to have unique names for each detail
line. To achieve this I use the day and line number as part of the
name. Given my code I would expect that I would get something like
<label for='hrs'>Hours<input type='text' name='hrs1_1' style='width:2em'
/></label>. My result is <label for='hrs'>Hours<input type='text'
name='hrs_' style='width:2em' /></label> as you can see the name
attribute does not have the variable portion. I can see that the
parameters passed are comming in to the constructor correctly but the
member variables of my class are not being set. I can't see why, it
must be something real simple.

I have declared the class as follows:

class clsBlnkDetail
{
var $mTs;
var $mDay;
var $mLine;

function clsBlnkDetail($Day,$Line,$sheet="none")
{
//Debug code
$fp=fopen("debug.txt","w");
//End Debug code

if ($sheet != "none")
{
if($day > 6)
{
echo "There are only 7 days in a week";
return(0);
}

//member variable should be set here
$this->mDay=$Day;
$this->mLine=$Line;
$this->mTs=$sheet;

//Debug code
fwrite($fp,$this->$mDay." ".$this->$mLine);
fclose($fp);
//End Debugg code

}
}
function MkName()
{
return($this->mDay."_".$this->mLine);
}
function Build()
{
//echo "Blank detail line<br />";
echo "<label for='hrs'>Hours";
$widgitName="hrs".$this->MKName();
echo "<input type='text' name='$widgitName; style='width:2em' />";
echo"</label> <br />";
}
}

Jul 17 '05 #1
1 1293
Charles Russell wrote:
Given my code I would expect that I would get something like
<label for='hrs'>Hours<input type='text' name='hrs1_1' style='width:2em'
/></label>. My result is <label for='hrs'>Hours<input type='text'
name='hrs_' style='width:2em' /></label> as you can see the name
attribute does not have the variable portion. [snip] if ($sheet != "none")
{
if($day > 6) ^^^^
Don't forget that variable names are case sensitive. This test will not
trigger when $Day > 6; the code will also produce a warning when
error_reporting is set to E_ALL.
{
echo "There are only 7 days in a week";
return(0);
}

//member variable should be set here
$this->mDay=$Day;
$this->mLine=$Line;
$this->mTs=$sheet;


You're still in the first if() block, so if you didn't pass a non-"none"
$sheet parameter, this will never be executed and your member variables
will never be set.

I do, however, get the expected results with your code when passing a
parameter:

$foo = new clsBlnkDetail( 1, 1, 'notblank' );
$foo->Build();

-- brion vibber (brion @ pobox.com)
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gama Franco | last post by:
Hi, I've been developing this API, but now I get stuck in a compiling error and I'm out of ideas. Some comments are welcome. The hierarchy is bases in three classes, and I will explain it...
5
by: August1 | last post by:
This is a short program that I have written from a text that demonstrates a class object variable created on the stack memory and another class object variable created on the heap memory. By way...
2
by: Gary | last post by:
Hi, I am a Chinese student, I have a problem with the following code //The follwing code in StaticSearch.h: // template <class Type> class dataList; // template <class Type> class Node ...
6
by: Nafai | last post by:
Hello. I want to do something like this: class A { // It's virtual protected: float* data; int n; public: A(int a); virtual float* createData(); //...
3
by: Lionel | last post by:
I believe I must have a c++ syntax or packaging problem. I have to reproduce my problem here as I can't disclose some of the original information, hopefully I don't lose anything: class A {...
15
by: Alfonso Morra | last post by:
Hi, I have some code from an example, that I want to retrofit into my project. The code from the example has the following line: SharedAppenderPtr myAppender( new...
8
by: silversurfer2025 | last post by:
Hello everybody, I had this problem several times now and did not yet get the reasoning behind it. I have a class with a pointer as member variable, lets say a float array. Furthermore, I have two...
6
by: B. Williams | last post by:
I have a problem dealing with class template where I was to write a class and after submitting the class, this is the feedback I got back from the instructor. I don't really understand it. Can...
7
by: dragoncoder | last post by:
Hello experts, I have the following code me. =cat mystring.h #include<iostream> using namespace std; class mystring {
13
by: Jeroen | last post by:
Hi all, I'm trying to implement a certain class but I have problems regarding the copy ctor. I'll try to explain this as good as possible and show what I tried thusfar. Because it's not about a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.