Home > Archive > PHP Programming > October 2005 > Class in class?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Tadeusz S. 2005-10-25, 6:56 pm |
| Hello
In Pascal, I use constructions like that
var SomeVar =3D object
SomeVar2 =3D 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.
--=20
greets
Tadeusz
| |
| fipaj1992@gmail.com 2005-10-25, 6:56 pm |
| Nie mozesz czegos takiego zrobic. Tylko... zamiast pytac pr=F3buj!
:)
You can't do that ;)
| |
| fipaj1992@gmail.com 2005-10-25, 6:56 pm |
| > Tylko... zamiast pytac pr=F3buj!
sorry, nie doczytalem ;)
PS. Po co ci ta klasa w klasie? Moze wystarczy funkcja eval(), czyli
wykonianie kodu przekazanego w argumencie?
| |
| Katipo 2005-10-25, 6:56 pm |
|
"Tadeusz S." <tadeusz@toznika.jca.iserwer.pl> wrote in message
news:435e5f80$1@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
| |
| Chung Leong 2005-10-25, 6:56 pm |
| 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
)
)
|
|
|
|
|