470,874 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

Class in class?

Hello

In Pascal, I use constructions like that

var SomeVar = object
SomeVar2 = object
end;
end;

etc., so I could put my object into another
object. Is this possible in PHP?
Some like:

class NameOfClass
{
class AnotherClass
{
}
}
?

The construction above is invalid, I tried.
But maybe I can do that another way?
TIA.

PS: sorry for my english.

--
greets
Tadeusz
Oct 25 '05 #1
4 1516
Nie mozesz czegos takiego zrobic. Tylko... zamiast pytac próbuj!
:)

You can't do that ;)

Oct 25 '05 #2
> Tylko... zamiast pytac próbuj!

sorry, nie doczytalem ;)

PS. Po co ci ta klasa w klasie? Moze wystarczy funkcja eval(), czyli
wykonianie kodu przekazanego w argumencie?

Oct 25 '05 #3

"Tadeusz S." <ta*****@toznika.jca.iserwer.pl> wrote in message
news:43********@news.home.net.pl...
Hello

In Pascal, I use constructions like that

var SomeVar = object
SomeVar2 = object
end;
end;

etc., so I could put my object into another
object. Is this possible in PHP?
Some like:

class NameOfClass
{
class AnotherClass
{
}
}
?
Are you talking about inheritance? If so try this:

class AnotherClass
{
}
class NameOfClass extends AnotherClass {

}

The properties and methods of AnotherClass, provided they are not declared
as private (PHP 5 and later), are now accessable as though they were
declared in NameOfClass
Oct 25 '05 #4
Unlike compiled languages like Pascal, you don't need to define
structures. All you have to do is set the properties as though they
exist. Autovivication will take care of the rest.

Example:

<?php

$a->b->c = "Something";
$a->d[] = "Something else";
$a->b->e = "Gowno";

print_r($a);

?>

Result:

stdClass Object
(
[b] => stdClass Object
(
[c] => Something
[e] => Gowno
)

[d] => Array
(
[0] => Something else
)

)

Oct 25 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fernando Rodriguez | last post: by
18 posts views Thread by John M. Gabriele | last post: by
13 posts views Thread by Bryan Parkoff | last post: by
8 posts views Thread by Bryan Parkoff | last post: by
21 posts views Thread by Jon Slaughter | last post: by
5 posts views Thread by Andy | last post: by
3 posts views Thread by Hamilton Woods | last post: by
reply views Thread by emin.shopper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.