Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




How To Get The Names Of All Sub Objects?


My example:

$person->telnumber->value
$person->faxnumber->value
$person->???

The names of the objects "telnumber" and "faxnumber" (and further
possible subobjects) are not known for me.

How can I get the names of all subobjects of an object?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Dynamic Variable Names For Objects
I need to use dynamic variable names but for objects.
As you know something like that works fine:

$variable="content";
$part="able";
echo ${"vari".$part};
// gives out content

but i need to use a database object after a mysql query something like that

$sqlresult= mysql_query("SELECT * FROM t_table_xy");
while (($obj = @mysql_fetch_object($sqlresult)) {
echo ${"obj->f_".$fieldname[1]};
}

but this dont work, I suppose because of the -pointer.
has someone an idea how to solve that ?

Setting Variable Names Using Field Names?
I'm having trouble creating dynamic variables using field names. Basically I got a heap of fields named after Players and I want to grab the field name and make a variable called it while assigning it a value from a post variable which is also the player name.

This is the code I'm using:
$result=mysql_query("SELECT * FROM playerstats");

while($fld = mysql_fetch_field($result))
{
if ($fld->name!='match_id' && $fld->name!='opponent' && $fld->name!='map')
{
$fld->name=$_POST[$fld->name];
}
}

Using Database Objects Within Other Objects. Inefficient?
I've defined a Database class with methods to call mysql_query(), etc. The connect() method makes a persistent connection. I've also defined a Member class to hold functions and data for users. PHP Code:

COM Objects
I'm trying to use MSCOMM32.OCX, but I got an error "Fatal error:
Uncaught exception 'com_exception' wih message 'Failed to create COM
object 'MSComm32.OCX' : Incorrect syntax'

The OCX is present on the system and I could succesfully use it
through visual basic.

PHP Objects
How PHP objects are passed from one page to other.

How Can Two Objects
Problem: pointers (like in C and C++) do not exist in PHP. How can you create two objects which point to eachother? I tried using references, but it seemed not to work. Does anybody know a solution?

Php 5 Objects
I created a php class in charge of doing mysql queries and when this query is called it returns an object of the type "myddl_result", this second object is passed the resource of type mysql_result and if i debug the whole thing i seems allright until the __construct is complete, after that, the __destruct is called for i don't know which reason and the rest is executed normally.

At that point my resource is of type unknown and can't be used anymore... I really need help on that please... i don't understand whats happening even after reading the php website 2x about php 5 objects. PHP Code:

Objects In PHP
Im using objects in PHP for the first time and have a question about
the following script.

$new_grad = new graduate();
$new_grad->set_fn($_SESSION['first_name']);
$new_grad->set_sn($_SESSION['surname']);
$new_grad->set_username($_SESSION['username']);
$new_grad->set_password($_SESSION['password']);
//etc

The sript is used to set up user accounts when they sign up for my
system.
HOWEVER I am concerned about the following scenario. Say if two or
more users are setting up accounts at roughly the same time.
The first person presses 'submit' so

$new_grad = new graduate();

Php And C++ Objects
i wanted to know whether it is possible to instantiate c++ class
objects and use them in php code ? can anyone pleez point out to some
docs on the net which refers to this particular problem ?


Bad Names
I have a program that extracts text from a file. But when it extracts the letter “ and some other letters, it outputs them like this: "IllidanĀ“s Revenge". But it first put it into the db

Accessing COM Objects
I am trying to access another windows application using php/COM, and it works great for single string values, but when retrieving a list of "Devices", it returns an object, and I am not sure how to deal with this in php. In ASP, this is how you would access the data: Code

Referencing Objects?
Fairly new to OOP and PHP5.

My question;

Maybe I am not thinking about this the right way? How do I reference a
variable or object(?) from one function to another in a class? Or how
do I pass the variable from one function or method to another? Am I
doing this right in the example below? How would I pass a variable from
one function to another?

Example .....

Recursivity With Objects
I am trying to do a script that is must print a tree of object (my
objects are some comments).

For more details, a "comment" is an object which can be at the top of
the tree (father), or which can be an answer to another comment
(children). There is no limit in father-children relation (a father can
have children, which can have children, which ...).

I have made 2 object, the comment and a comment contener (just an
array). Un comment is simply composed with a texte and an id.

Here is the code and my test failure....

Extract() And Objects
Is it possible to use extract on an array of objects so that the objects
are available in the local variable space?

Php Using Javascript Objects
I want to initialize a TEXTAREA with text depending on the values
already selected in other areas - input type=TEXT or SELECT.

How can I set a PHP variable with a value retrieving those HTML object
values?

Array_keys With Objects
I have a gallery object which contains an array of image objects. I
would like the image objects to be able to return their adjacent
siblings in the array so that, for example,
$gallery->images[3]->nextImage() would return $gallery->images[4]. The
images each contain a reference to their parent (i.e. the gallery
object) so I tried using array_keys(). This is a method of the image class:

function nextImage() {
$pos = array_keys($this->parent->images, $this);
return $this->parent->images[$pos[0]+1];
}

The array_keys call *should* find the current object ($this) in the
array and return an array containing a single value which is the index
of the current image in the images. But instead I get "Fatal error:
Nesting level too deep - recursive dependency?"

I suppose this has something to do with the cyclic references. Can
anyone suggest a way around this or any other way for an image to access
it's siblings?

NEW: XML Application Objects
I've just released the first distribution for an open-source project
called XML Application Objects (XAO). It's the result of working with
XML/XSLT in PHP for a couple of years now. Although this is an alpha
release, the concept itself has gone through a lot of refinement and is
now ready for prime time.

The publication of the project itself was partially motivated by the
discussions that took place in this thread (A Complete List of PHP
Template Engines?) which basically sees me arguing for the usage of
standards (XSLT) rather than having to learn a proprietary new
templating system every time you work on someone elses PHP app.

This project is the result of much blood, sweat, and tears so I hope
someone out there finds it useful. I have made documentation a paramount
considderation for the XAO API because I'm keen for it to be another PHP
success story. The website has a tonne of information so I'm not gonna
try and promote XAO in this message.

Sessions And Objects
I am using sessions to pass the main object from one page to another in a shopping cart script. The main object is $cart PHP Code:

Global Objects?
how to declare an object globally? So I can use it inside other objects?

Refactor Objects
Do we know anyone else who writes PHP code? There is too much work to
do, especially if Costin and I are going to join our software
together.

The easiest way for us to join our software together is through high
level wrapper classes that take other classes for arguments. Costin
and I could move toward joining the software one package at a time.

I've currently got a big SQL class and a big Form class. Both need to
be refactored into smaller objects. Doing so would allow more code
reuse and also make things more modular, flexible, and stable. The
uppermost class could be preserved as a command class. We could follow
the Command Design Pattern, and then Costin and I could use just those
commands, which would have differnt meanings in our code, depending
what object we give the command class.

Forms, database connectivity, etc, one slow step at a time we could
join our code.

I think Costin has a security class that could be refactored and used
for both pieces of software. Again, the right way to do it is to turn
the top level class a wrapper for lowever level commands.

I'd also like to make a separate piece of software that gets info from
the data store and returns it as a 2 dimensional array as a SOAP XML
stream. Costin and I could both come to rely on it, and our own
software wouldn't have to worry about it. The nice thing is the data
fetching software would then be truly agnostic about where the data
was, given the right module it would fetch it out of anywhere -
database, flat files, hash tables, multiple XML files.

But I need help. I need some other person who knows a little PHP and
has some time and feels like helping out. Someone who wouldn't mind
refactoring the classes. If we could find such a person, they could
refactor my code and Costins and in the process intergrate Costin's
code and mine.

Objects And Queries
I have tried to join 4 tables with a SQL line and fetch the data as a object while($edit = mysql_fetch_object($result)) My problem is this, I need to lable a object somthing like this $edit->products.id but it doesn't seem to work very well the printed result is .id any suggestions?

Freeing Objects
Let's say that I've the following code (pseudo code cause this is a
question about how php gc works)

file class.php
------------------
class ClassX {
//var $F_strDB;
others vars here

function DoWathEverDBJob(){
connectToDB (using class variables as $F_strDB)
queryDB
process results
(# 1)
return (true-false, not an array nor a result set)
}

} //class

file test.php
------------------
$classX = new ClassX;
$classX ->DoWathEverDBJob();
(# 2)

Questions

-Should I have to call mysql_free_result in (# 1)

-Should I have to "destroy" $classX in any way in (# 2)

I used to think that objects and queys would be destroyed
automatically, but i'm not sure right now...

Sessions And Objects
I'm currently building an object-oriented shopping cart with PHP 4.3.2 and
MySQL 4.0.14.

I am looking at storing a Cart object within a PHP session, however I am not
completely sure on the best way to achieve this. I have read up and there
seems to be varying advice. Should I need to serialise and unserialise the
object or is this automatic and should I be using session_register()? For
reference, register_globals is off.

Arrays Of Objects
I'm having considerable trouble finding the proper syntax for accessing
a specific element from an object which is in an array. Here is my
pertinent code snippet:

$courses = array(); // define empty array
while(($row = mysql_fetch_object($result))) {
array_push($courses,$row); // push row object onto the array
}
echo "<p>$courses[0]->name</p>
"; // access first object's name

This does not give me the string I want, which is name of the first
course in the array. I verified $courses[0] is an object. One of the
members of the object is 'name'. How do I access the name of the first
course?

I tried:
$courses[0]->name
${courses[0]}->name
$courses[0]['name']
${courses[0]->name}

Create Php Objects From Xml
What i want to do
is create objects from an XML file.
basically my tags are all object elements or attribute values ie each
indent is a new object. the classes for these objects are already
written, just the objects need to be created
eg

<object1>
<value1>23</value1>
<value2>hello</value1>
<object2>
<value3>test1</value3>
<value4>23</value4>
<object3>
<value1>100</value1>
<object3>
</object2>
<object2>
<value3>test3</value3>
<value5>50</value5>
</object2>
</object1>

i have classes for object1,2,3 that have definitions for the various
types that they will have.

what this should return (create) is an object of type object1. in this
there is an array of 2 objects of type object2 along with attributes
of type value1 and value2 with their values.

the first instance of object2 also has a instance of object3 which
has an attribute of type value 1 which equals 23

i have looked at all the exparsing, but it is more for viewing, and i
cant get them adaptd

basically just need something that can break the file down into its
indenting. there are only 3 objects deep in the xml before we reach
nodes with no children.

Adding Objects
I would like to know how i can add the following function calls together to produce one.

      $encounterone=&$lab_obj->searchEncounterLabResults($keyword,$pagen->MaxCount(),$pgx,$oitem,$odir);
      $encountertwo=&$labs_obj->searchEncounterLabResults2($keyword,$pagen->MaxCount(),$pgx,$oitem,$odir);

How can I add these two to get one output.-- $encounter

which i can use here

while($zeile=$encounter->FetchRow()){

display script
}

Comparing Objects
I've got an array of objects that are instantiated based on an ID, but it's possible that multiple objects of the same ID may be added to an array.  I've tried using array_unique to get rid of duplicates, but if the object contains a null data field, it throws some error messages.

How do I get PHP to compare objects by a certain field rather than every variable (null or set) declared in an object?

Form Names And PHP
Does PHP handle form names? Suppose I have two forms on one page, named form1 and form2. I pass them to the same php script via the same method. Can PHP distinguish which form was used? How?

Irish Names
I have a problem sending email from a for supplied as html

if in the person has to supply an additional Name field it
works if his name is Smith but if it is O'Brian it fails.

is there away to overcome this apostrophe problem.

Pdo Get Field Names
I'm using PDO for the first time. I want to get the field/column names
from a SELECT query. I can get the names from the associative array
returned by fetch(). But how do I get the field names if the SELECT
query returns no rows? I could do this before with the
xxxx_fetch_field() functions.

Here's a condensed version of my code:

// query the database
$DbToQuery = new PDO("sqlite::memory:");
$DbToQuery->query("CREATE TABLE MyTable (MyField TEXT)");
$sql = "SELECT * FROM MyTable";
$result = $DbToQuery->query($sql);
// Get the number of columns
$Cols = $result->columnCount();
// Loop through the results
$countrows = 1;
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
if($countrows == 1) {
// Print column names
print join(",", array_keys($row));
}
$countrows++;
// handle the row data
// ...
}

How To Get Value From $_POST['$names'] ?
how do i correctly get the value from this:

for ($names = 0; $names < count($_POST); $names++) {
echo($_POST['$names']);}

Variable Names
I want to create a series of variable names in the form of $dist_1, $dist_2, $dist_3 etc....How can I do this using a loop? A scaled back example (ie, forgetting about the for loop syntax) of what doesn't work is:

$i = 1;
$dist_'$i' = 50;
echo $dist_1;

I have tried all sorts of variations like $dist.$i, $dist"$i", but none of them seem to work. I could create an array dist[$i] but that is going to cause problems elsewhere.

Subdomain Names?
i have a website which is functional since 2006. But now i just want to add some new services like SMS and so on. i want users to type sms.mywebsitename.com to access the page with the sms service. but i am not aware of how to make the subdomain i mean sms prefix.

Page Names?
Is it possible to somehow read a page title based on the page you are one.

for example:

if the page is: mainpage.php

so inside the mainpagephp it would say:

include "pagetitles.inc";

and inside the the pagetitles.inc file it would say something like:

if whateverpage
     echo $pagetitle = "Main Page";

Domain Names
I am writing a reporting tool for the open source project Dansguardian, right now I am taking a URL that a user has visited and need to compare it to a blacklist, which contains just domain names (i.e. - phpfreaks.com). I currently have some code which does this but it does not work for https URL's. Here is the code:

Add Commas Between Names
i've got a script that pulls first name, last name, and suffix from a DB query and echos them only if they are not null. the names are cross-referenced by id number from two other tables. it displays the name pieces that are not null for each "job", and the jobs and names are determined by another id number for an individual issue page. an example of the output is here: Code:

Column Names
how can i get the column names of ms access table?

Objects - Inheritance - OVERLOAD!!!!!!
Does anyone know offhand if it is possible to call the parent class' overloaded function from the child....

....i.e. if I have a class called A with a member function xyz(), and then define a class B which inherits from A... and redefine the function xyz() in B.... then is it possible for B->xyz() to call A->xyz() from within itself?

Why? Well I want to 'add' to the funcionality of a base class. the base class returns a string, and my child class wants to take the parent string and add bits to it.

Is it just a case of calling xyz() from B ? Won't that just cause reccursion on itself? I need something like baseclass->xyz().

Passing Objects Between Pages
I'm using an object to cart stuff around with me on several html pages, or at least i'm trying to. It must be simple but I can't for the life of me work out how to to pass it round.

I've tried adding it to a href address like a standard variable, but then what does it equal?

Insert Objects Into MySQL ?
I'd like to know if there is a way to insert any object into a mysql-database.PHP Code:

Accessing Objects In Arrays
Is it possible to access the properties of an object when it is stored inside an array?

sort of like this...
echo array[object->property]...

PHPClass Form Objects?
Are there any PHPClass scripts that provide us with a different look &
feel for web page controls such as buttons, text boxes, dropdown
lists, etc.?

Objects, Arrays, And Loops
I'm working on an auto-schedular for my college's Music Festivals. I just started on this tonight. I'm starting by reading all the information into variables. For starters, I have a School class. The script should read data from the database into School objects for later use. I've never used objects in PHP before, but I've used them in several other languages. I read data from the database into the School objects using a loop, with a loop invariant
called $schoolCount. I created a print statement so that I could see
if the data was being correctly assigned to the School objects, but I
think it's printing the value of the loop invariant instead of the
school name like I want. I'm not sure why. Here's my code:

Problem With Array Of Objects
I have a small problem with array and objects:

$a = new A();
$b = new A();
$c = new A();
$d = new A();
$e = new A();

$ar = array($a, $c, $d);

There is a method inside A, which would need the information, that is
that instance ($this) of A a member of array $ar.

I thought, that this could have been tested easily with

if (in_array($this, $ar)) ...

But it is not working.

Is there any easy solution for this?

Classes And Objects - Please Explain
PHP is my first serious programming language (have some exp w/
javascript), so this notion of classes and objects confuses me. What's
a good way for me to understand this?

Multiple Mysql Objects
I have a system which needs to connect to two separate databases. I've created a class to handle my database connections but one thing i've ran into is that calling a second instance of a class will overwrite my previous database connection. Example.

My 2 databases have tables titled orders. Database A has 20 orders and Database B has 40. I call my mysql objects.

$mysqlObjA = new mysql($sqlhost,$sqluser,$sqlpass,$dbA);
$mysqlObjB = new mysql($sqlhostB,$sqluserB,$sqlpassB,$dbB);

then i execute my queries. Code:

Confusion About Classes And Objects
Using PHP 4.4.4, I have a class defined like so

class CUserItem {
var $m_id;
var $m_children_arr;
function CUserTOCItem($p_id)
{
$this->m_id = $p_id;
$this->m_children_arr = array();
} // CUserItem
function addChild($p_child) {
array_push($this->m_children_arr, $p_child);
} // addChild
function numChildren() {
return count($this->m_children_arr);
} // numChildren
} // CUserItem

then in a separate bit of code, I have an associative array of
objects, with the key being the id and the value being the object.
Unfortunately, when I try and manipulate the objects in the array, it
doesn't take ...

$item = new CUserItem(1);
$item2 = new CUserItem(2);
$toc_items_arr[1] = $item;
$item->addChild($item2);
print $toc_items_arr[1]-

Quote:

Sorting Array Of Objects?
I'm reading an XML file using SimpleXML and xpath into an array. What I'd like to do is sort the array based on a specific element's value. For instance, an XML that has some elements like:

<CUST>
<NAME>ABC Co.</NAME>
<LVL>A1</LVL>
<STATE>CA</STATE>
</CUST>
<CUST>
<NAME>ACME</NAME>
<LVL>A2</LVL>
<STATE>CA</STATE>
</CUST>

is read into an array. Because I'm using SimpleXML, the array elements are each SimpleXML objects. I want to then sort the array based on the value of the LVL element (i.e. A1's, then A2's, etc.). Every item in the array will contain this element. Is this possible?

Array Of Objects Problem
I'm having problems calling methods inside an array of objects. It
seems that I can't understand very well how "&" works

The code which follows, prints out

ClsSet Constructor
El nombre del objeto es:
El nombre del objeto es:
El nombre del objeto es:

whereas I expected

ClsSet Constructor
El nombre del objeto es: cls1
El nombre del objeto es: cls2
El nombre del objeto es: cls3

Where i'm wrong?

class ClsX{
var $F_name;

function ClsX($name){
$this->Fname = $name;
}
function GetName(){
return $this->F_name;
}
}//class

class ClsSet{
//comentarios de clase;
var $F_array_of_obj = array();

function ClsSet(){
echo "ClsSet Constructor<br>";
}
function AddObj(&$obj){
$this->F_array_of_obj[] =& $obj;
}

function Names(&$obj){
//print_r($this->F_array_of_obj);
for ($i = 0; $i <= (count($this->F_array_of_obj)-1); $i++){
//print_r($object);
$object =& $this->F_array_of_obj[$i]; //I've tryied with and
without &
echo "El nombre del objeto es: ".$object->GetName().'<br>' //It
actually doesn't call GetName()
}
}


Copyright © 2005-08 www.BigResource.com, All rights reserved