473,587 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tricky problem with setting variables within classes

Problem: I try to store data in a objects field and read it out again.
Sounds easy, yeah. But its a bit tricky here.... ;-)
This is the class Customer.php with some setter and getter functions to
store customers data within an object.
It works.
Furthermore, it includes a synchronize method, which calls the
individual setXXX function and takes the data
from the $_POST or $_GET var.
Therefore the fieldnames from the HTML form and objectfields have to be
equal, so that data for $obj->fieldB
can be found at $_GET['fieldB']. Well, no problem, yet.

sample:
$obj->synchronize("f ieldA");

will call the function setFieldA($_GET/POST['fieldA']) from
the objects methods
So this is the Customer.php (shortened to the basics we might need here):

--CODE-----------------------------------------------

...

// setter and getter of a class customer

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

function setName($name)
{
if(strlen($id) <= 40) {
$this->name = $name;
return true;
}
else {
return false;
}
}

...

// $obj.synchroniz e calls the setter function set{$PARAM} of a class
object, to fill the object with Data

function synchronize($pa ram, $method="POST")
{
$functionName = 'set'.ucfirst($ param);
if (method_exists( $this, $functionName)) {
$buf = null;
if(strtoupper($ method)=="POST" ) {
$buf = $_POST[$param];
}
elseif(strtoupp er($method)=="G ET") {
$buf = $_GET[$param];
}

if($buf <> null) {
return call_user_func( array($this, $functionName), $buf );
}
else {
return false;
}
}
else {
return false;
}
}

...
-----------------------------------------------------

Well. The class Customer.php itself works!
But now, I try to send data to the object via the synchronize function.
To do this, I use the following sample script, which receives data via
method GET by URL as you can see:
.../step2.php?name= JohnDoe
--CODE-----------------------------------------------

<?php

include_once 'Customer.php';

$newCust = new Customer();
$method = "GET";

if (!$newCust->synchronize("n ame",$method)) {
printError( "Der Name ist nicht korrekt!");
};

print "Result: ".$newCust->getName();

?>
------------------------------------------------------

Well thats all.
It should send "JohnDoe" to the $newCust->name variable and print out:

Result: JohnDoe

But in fact, it prints: Result:
To make it more clear what I need:
The expected result could be reached by doing the following from the
step2.php:

$newCust->setName($_GE T['name']);

But I have so many fields and forms which change often, that this is not
an effective way!
I need to do this via my synchronize method, that calls the
corresponding setXXX function automatically.
Well, the call of the function in the class itself works, but I cannot
read the object's field at the end!
I tried putting a >>print "test: $name"<< within the setName function
and it seems to work correctly!
So the value is sored somewhere, but I don'T know where it is stored!
Maybe I write it to a wrong new object? is $this wrong? do I need to
point to $parent?

I hope anybody can help me!?

Thanks in advance,
Lars
Jul 17 '05 #1
3 2146
Talk about making things hard to make things easy...
Jul 17 '05 #2
Chung Leong wrote:
Talk about making things hard to make things easy...


Thanks for the information... ;-)
Jul 17 '05 #3
Lars Plessmann wrote:
Chung Leong wrote:
Talk about making things hard to make things easy...


Thanks for the information... ;-)


okay. problem solved by myself.
Jul 17 '05 #4

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

Similar topics

9
4944
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or...
8
9699
by: David McDivitt | last post by:
I need to set tabs on java generated pages. Pages have four sections: header, sidebar, body, and footer. The sidebar and body change dynamically. The tab key must go to anchors, fields, and buttons doing all in the header first, all in the sidebar second, etc. A base page contains includes for all the pieces and has the body tag. I am...
25
3384
by: PyPK | last post by:
What possible tricky areas/questions could be asked in Python based Technical Interviews?
7
2028
by: Nicole | last post by:
Hi I'm trying to use a function to set a session variable. I have three files: The first file has: <?php session_start(); // This connects to the existing session ?> <html> <head>
13
2740
by: Steve Jorgensen | last post by:
== On Error Resume next, and Err.Number == If you want to call one of your procedures from another procedure, and check for errors afterward, you mayimagine that you should write code something like this... On Error Resuse Next MyFoo 123 lngErrNum = Err.Number On Error Goto 0
3
3844
by: Michael Roper | last post by:
Is there a C# approach that allows you to define locals with program lifetime? That is, I don't want to have to expand the scope of a variable just so I can make it persistent. For example, something like: class myClass { int iCallCounter = 0; int CallCounter() { return ++iCallCounter }
5
1547
by: Javier Campos | last post by:
WARNING: This is an HTML post, for the sake of readability, if your client can see HTML posts, do it, it doesn't contain any script or virus :-) I can reformat a non-HTML post if you want me to (and if this doesn't see correctly with non-HTML viewers) Ok, I'm fed up with this so I'll explain the situation here and my approach (which sucks),...
0
2182
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into problems later). Apparently Point is a struct, a value type, and it does not behave like a classic structure (in my mind's eye, and see below)....
5
13336
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.