datagott > internet.* > internet.www.server-side

Marcel (08.11.2006, 16:28)
I have a person class adn i want to derive an object of that class on one
page and pass that object to a next page but that does not work for me and i
do not understand why.

Here is de code:

class.person.php
-----------------------------------
class person {

private $_name;

public function setName($name) {

$this->_name = $name;

}

public function getName() {

return $this->_name;

}

}
--------------------------------------------

person1.php // here is the object created
-------------------------------------------
require_once("class.person.php");

$p = new person();

$p->setName("Jim");

$safep = urlencode(serialize($p));

header("Location:person2.php?data=".$safep);

exit;

person2.php // page where the object is transfered to
---------------------------------------------------
require_once("class.person.php");

$p = unserialize(urldecode($_GET['data']));

echo $p->getName();
ZeldorBlat (08.11.2006, 17:07)
Marcel wrote:
[..]
> exit;
>> person2.php // page where the object is transfered to

> ---------------------------------------------------
> require_once("class.person.php");
> $p = unserialize(urldecode($_GET['data']));
> echo $p->getName();


Difficult to say since you haven't told us what doesn't work. As in
you get some error that you can't unserialize it? Or no error at all
(as in your error reporting is turned off)?

My guess would be that
$p = unserialize(urldecode($_GET['data']));
should really be just
$p = unserialize($_GET['data']);

But I didn't test it.
Marcel (08.11.2006, 17:18)
"ZeldorBlat" <zeldorblat> schreef in bericht
news:3680
> Marcel wrote:
> Difficult to say since you haven't told us what doesn't work. As in
> you get some error that you can't unserialize it? Or no error at all
> (as in your error reporting is turned off)?
> My guess would be that
> $p = unserialize(urldecode($_GET['data']));
> should really be just
> $p = unserialize($_GET['data']);
> But I didn't test it.


Yes you are right, the errorcode i am getting is:

Fatal error: Call to a member function getName() on a non-object in
D:\public_html\person2.php on line 7

Regards,

Marcel
Marcin Dobrucki (08.11.2006, 17:29)
Marcel wrote:
> I have a person class adn i want to derive an object of that class on one
> page and pass that object to a next page but that does not work for me and i
> do not understand why.

....
I tried this code, and it works just fine. You didn't include the rest
of the code, so maybe there is something there that breaks it?

<?php
class A {
var $name;
function A($name) {
$this->name = $name; }
function getName() {
return $this->name; }
}

$a = new A("my name");
$a_serialized = urlencode(serialize($a));
header("Location: obj2.php?data=".$a_serialized);
?>

and:

<?php
class A {
var $name;
function A($name) {
$this->name = $name; }
function getName() {
return $this->name; }
}

$a = unserialize(urldecode($_GET['data']));
echo get_class($a);
echo "<br>";
echo $a->getName();
?>
Marcin Dobrucki (08.11.2006, 17:31)
Marcel wrote:

> Yes you are right, the errorcode i am getting is:
> Fatal error: Call to a member function getName() on a non-object in
> D:\public_html\person2.php on line 7


One step at a time: what do you get out of "urldecode" and then what
do you get from "unserialize"? Check the return values.
Marcel (08.11.2006, 17:40)
"Marcin Dobrucki" <Marcin.Dobrucki> schreef in
bericht news:4821
[..]
> $this->name = $name; }
> function getName() {
> return $this->name; }
> }
> $a = unserialize(urldecode($_GET['data']));
> echo get_class($a);
> echo "<br>";
> echo $a->getName();
> ?>


Hi Marcin,

I tried your example but i am getting the same error: Call to a member
function getName() on a non-object in

Maybe it is a php.ini issue? I do not know what can be another reason....
maybe magicquotes have to do something with this?

Do you have any ideas?

Marcel
Marcel (08.11.2006, 17:53)
"Marcin Dobrucki" <Marcin.Dobrucki> schreef in
bericht news:4821
> Marcel wrote:
>> Yes you are right, the errorcode i am getting is:
>> Fatal error: Call to a member function getName() on a non-object in
>> D:\public_html\person2.php on line 7

> One step at a time: what do you get out of "urldecode" and then what do
> you get from "unserialize"? Check the return values.


It seems the unserialize function does not seem to work properly... i will
do a little research at that first ok...
thehuby (08.11.2006, 19:59)
Wouldn't you be better using sessions?

If you register a session variable you won't need to use the query
string and you won't need to serialize and deserialise it.

Take a look at [..] for some
more details.

Rick
[..]
Michael Fesser (08.11.2006, 20:02)
..oO(Marcel)

>I tried your example but i am getting the same error: Call to a member
>function getName() on a non-object in


error_reporting set to E_ALL? What browser do you use?

>Maybe it is a php.ini issue? I do not know what can be another reason....
>maybe magicquotes have to do something with this?


First you should fix the error in the redirect. The Location header
requires an absolute URL.

Micha
Marcel (09.11.2006, 10:27)
"Marcin Dobrucki" <Marcin.Dobrucki> schreef in
bericht news:4821
> Marcel wrote:
>> Yes you are right, the errorcode i am getting is:
>> Fatal error: Call to a member function getName() on a non-object in
>> D:\public_html\person2.php on line 7

> One step at a time: what do you get out of "urldecode" and then what do
> you get from "unserialize"? Check the return values.


The unserialize function in person2.php did not return anything. I tried all
scripts on another server with the same PHP version installed and there
everything just worked fine. One difference i can think of is the fact that
the server where my script did not work is protected trough https
Marcin Dobrucki (09.11.2006, 11:06)
Michael Fesser wrote:
> First you should fix the error in the redirect. The Location header
> requires an absolute URL.


True. But it seems to work with relative URLs as well.
Jerry Stuckle (09.11.2006, 15:02)
Marcel wrote:
> "Marcin Dobrucki" <Marcin.Dobrucki> schreef in
> bericht news:4821
> The unserialize function in person2.php did not return anything. I tried all
> scripts on another server with the same PHP version installed and there
> everything just worked fine. One difference i can think of is the fact that
> the server where my script did not work is protected trough https Marcel,


http vs. https shouldn't make a difference, unless you're trying to mix
the two. That is, storing it in the session when using http and reading
it back with https (or vice versa).

Also, is the domain *exactly* the same? i.e. you don't have one as
[..] and the other as example.com?
Michael Fesser (09.11.2006, 18:00)
..oO(Marcin Dobrucki)

>Michael Fesser wrote:
>> First you should fix the error in the redirect. The Location header
>> requires an absolute URL.

> True. But it seems to work with relative URLs as well.


A bug is a bug and should be fixed, especially if you're searching for
the reason of another bug, which could be caused by the first.

Micha
Jerry Stuckle (10.11.2006, 06:15)
Michael Fesser wrote:
> .oO(Marcin Dobrucki)
> A bug is a bug and should be fixed, especially if you're searching for
> the reason of another bug, which could be caused by the first.
> Micha


Yep, bugs need to be fixed. But how many times do people have to tell
you that PHP is working exactly according to the RFC's?

Additionally, it's not just PHP. It's every browser on the market.
Session ID's are kept in cookies. And even the browsers agree that
example.com is not the same as [..] - and will not send a
cookie generated by one host to the other.

If you don't like it, fine. Put in your own RFC and get the entire
internet to change. But don't keep complaining about it being a bug
just because it doesn't work like *you* would like it to. It's been
like that for almost 40 years, since it was arpanet. I know for sure it
was like that in the early 70's when I was on arpanet. And that's the
way it's designed to work.

As much as I hate to tell you, the internet does NOT revolve around Micha.
Michael Fesser (11.11.2006, 02:34)
..oO(Jerry Stuckle)

>If you don't like it, fine. Put in your own RFC and get the entire
>internet to change. But don't keep complaining about it being a bug
>just because it doesn't work like *you* would like it to.


RFC 2616, section 14.30 "Location":

| The field value consists of a single absolute URI.

Micha

Soortgelijke onderwerpen