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




How Do You Sort An Object Array By An Object Property?


array_walk($result, create_function('$a, $b', 'return (strtolower($a->{$section . "_name"}) < strtolower($b->{$section . "_name"}));'), $section);

I thought this would sort an object array by the property {$section . "_name"} (the variable $section has multiple values, hence, the object array might be "image_name", "video_name", "audio_name", "anything_name", but it will definitely exist, by whatever name comprises ${section}_name, in the object property within the object that makes up each array element), however, the sorting never takes place.

How can I ensure that the object array is always sorted by $obj->{$section . "_name"}?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Array Property Of Object With __get And __set - Is This A Bug?
I'm reasonably proficient with C#, and am starting with php5. I was happy
to learn of the __get and __set methods, but am encountering a problem using
them to set an object property of type "array".

Below is a simple example of the problem I'm having with a sample object
"Article", which has an array property "authors". As you can see, I can't
even use standard php array syntax to set a single author, even though the
same syntax outside of the object works perfectly.

Am I doing something wrong here, or is this a php5 bug .....

Problem Retrieving An Object From An Array And Calling A Method On The Object
Hello, I am using PHP 4.4.1 and am having problems retrieving an object
from an array of objects and then calling a method on it. Here are two
simple classes that I am using:

PHP Notice: Trying To Get Property Of Non-object
I am using a DOM parser to get information from an XML feed. The XML feed is generated based on inputs and changes with each call. I have a script that checks to get elements of choice and display them. My problem is that sometimes an element may not be there and throws this error:

Code: PHP Notice: Trying to get property of non-object

I have tried using the is_object function to check for this but it does not seem to work. Here is an portion of my code: PHP Code:

Using Zend And Object Property/functions Follow-up
With Zend, using PHP5, I am trying to acess property of an object that
is stored in a member variable. I'm quite new in using PHP5 and class functions but I haven't seen anything that could answer me. Would someone please tell me what I am doing wrong or link me to somewhere I may find some help please

DEMO:

class A
{

private $m_oObjectC = NULL;

function __construct()
{
$this->m_oObjectC = new B();
}

private function test()
{
// I canot see the attribute listing at the second ->
as if it could not read property.
// I know that like that, there is no way it may know
what is the current object
// but this is what my question is about, how to 'CAST'
// or whatever it take to get the class information.
$var = $this->m_oObjectC->FctClassC();
}
}

class B
{

function __construct()
{
$oObjectC = new C();

// Some manipulations

return $oObjectC;
}

}

class C
{

function __construct()
{

}

function FctClassC()
{
// Some manipulations
}

}

The Script Tried To Execute A Method Or Access A Property Of An Incomplete Object
Can anybody tell me wat this error means and how to solve it?

Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition cart of the object you are trying to operate on was loaded _before_ the session was started in c:/inetpub/wwwroot/temppro/show_product.php on line 204

__destruct() Destroy An Object That Contains A Reference To Another Object
i'm using PHP 5.1

I have two objects and the second one is using an instance of the
first.
As displayed in the example below, the Garbage Collector calls the
destruct method of the first class before the second even if the second
contains a reference to the other, so i can't complete all the
operations not having all "the code available"!

Ex.:

class MyFirstClass
{
public function __construct()
{
... operations...
}

public function __destruct()
{
echo "Destroyed MyFirstClass";
}
}

class MySecondClass
{

private $obj = NULL

public function __construct($obj)
{
... operations...
}

public function __destruct()
{
echo "Destroyed MySecondClass";
}
}

$obj1 = new MyFirstClass();

$obj2 = new MySecondClass($obj1);

// Result
// Destroyed MyFirstClass
// Destroyed MySecondClass

Test If An Item Is An Object Or A Reference To An Object
Using php 4.4.4, let's say I have an array of objects or references to
objects. If I picked out an arbitrary element, $n, how would I know
if that was an object or a reference to an object?

What Might Destroy An Object That Is A Member Of Another Object
At the top of one class I declare a security object:

var $securityObject = null;

In the constructor, I initialize a bunch of member objects. Because
I've had trouble with the security object, I also test to make sure it
has been initialized:

function IntfCommands() {
parent::IntfBasic();

$this->resultsObject->notes("We are now at the beginning of the
constructor for IntfCommands.");

$this->pageInfoObject = & $this->core->getObject("McPageInfo", "
IntfCommands");
$this->selectObject = & $this->core->getObject("ExteriorSelect",
"IntfCommands");
$this->arrangementsObject = &
$this->core->getObject("McArrangements", "IntfCommands");
$this->validationObject = &
$this->core->getObject("ExteriorValidation", "IntfCommands");
$this->userObject = & $this->core->getObject("McUsers",
"IntfCommands");
$this->optionsObject = & $this->core->getObject("SingletonOptions",
"IntfCommands");
$this->fetchObject = & $this->core->getObject("ExteriorFetch",
"IntfCommands");
$this->securityObject = & $this->core->getObject("ExteriorSecurity",
"IntfCommands");
$this->outputObject = & $this->core->getObject("ExteriorOutput",
"IntfCommands");
$this->fileObject = & $this->core->getObject("ExteriorFile",
"IntfCommands");

if (is_object($this->fileObject)) {
$this->fileObject->setFileObject("pathAccess");
} else {
$this->resultsObject->error("In the constructor of IntfCommands we
could not get an instance of ExteriorFile.", "IntfCommands");
}

Last Object Of Array
I have a script that is echo'ing the values of a mysql query using a while. What I need to do is right before the last value is echo'd I need to write "last item".

Is there a way to do this: figure out how many array values there are then out put all but the last one, then write some text, then write the last value of the array.

Storing Object Into Array - OOP
Can I store objects into an array?

$anArray[$index] = $anObject;
$anArray[$index]->aMethod();

I have problems executing the above code. Does anyone knows a better/correct way of doing it? How do I invoke a method belonging to that object?

Recurse An Array With An Object/s
I am using php4
And I have a class product
I create an array of productObjects that has 2 dimensions.
Generraly I am sorting my objects inside arrays and I need to some how
recurse those arrays to get to the objects.

To do that I am using the following method recurseArray()

function recurseArray($array) {
if(is_array($array)) {
foreach($array as $arrayValue) {
recurseArray($arrayValue);
}
}
elseif(is_object($array)) {
$object = $array;
return $object;
}
}

the problem with that is that when i try to do
$_product = recurseArray($productArray)
print_r($_product);

it won't pring anything. But if i do the pring inside the method like
that
....
elseif(is_object($array)) {
$object = $array;
print_r($object)
return $object;
}
....

Retrieving An Object From An Array
I have an array of objects, and I would like to retreive one of the
objects based on a given key and value (ie. name='john'). Is this
possible and if so what is the syntax?



Array, Object Problem....
In an object i have
$this->data as array of mysql query results(see example)

and a function in_multi_array() which isn't important.It just seraches for
$needle in a multidimensional array and returns bool

I have also these functions in an object

function &getID($needle)
{
foreach($this->data as $key=>$value)
if(in_array($needle,$value))
return $key;

}

function &getByValue($needle)
{

if($this->in_multi_array($needle,$this->data))
{
$id=$this->getID($needle);
$array=$this->data[$id];
}

return $array;

}

When you call $sample=$object->getByValue("something") and if "something" is
a result of a query (any field) then you get all the fields that belong to
that result in array

example:

DataBase:

id | name | lastname
--------------------------------------
1 John Smith
2 Mark Jones
3 George Burchnall

query="SELECT id,name,lastname FROM people"
after everything....

$this->data will be:
[data] => Array
(
[0] => Array
(
[id] => 1
[name] => John
[lastname] => Smith
)

[1] => Array
(
[id] => 2
[name] => Mark
[lastname] => Jones
)

[2] => Array
(
[id] => 3
[name] => George
[lastname] => Burchnall
)

and when I call $sample=$object->getByValue("Mark")

$sample will be array (
[id] => 2
[name] => Mark
[lastname] => Jones
)

How can I get multiple results back if I have more than one "Mark" in DB

I would like then that $sample would be [0] for this Mark we just retreived
and [1] for second and so on so on...

I think I made my self clear :))

Using Object Properties Or An Array For Value Storage?
I like the syntax of accessing object properties better then that of array indexes but i have read a few times that OOP is slower. Does that hold true in this case as well, using objects purely for value storage?

Convert An Associate Array To An Object?
Something like this, maybe?
function &array_to_object(&$ra, $class
= 'stdclass')
{
if (!is_array($ra)) trigger_error("not an
array", E_USER_ERROR);
if (!class_exists($class))
trigger_error("not a class", E_USER_ERROR);
$result = &new $class;
foreach (array_keys($ra) as $k) {
if (is_array($ra[$k])) {
$result->$k = array_to_object($ra[$k], $class);
} else {
$result->$k = &$ra[$k];
}
}
return $result;
}

Adding A Custom Object To An Array
Anyone have any idea what im doing wrong here:

$image = new Image();
$image->SetImageContent($imageRow['imageContent']);
$image->SetFileSize($imageRow['fileSize']);
$image->SetFileName($imageRow['fileName']);
$image->SetImageId($imageRow['imageId']);
$image->SetParentImageId($imageRow['parentId']);
$image->SetFileType($imageRow['fileType']);
$image->SetImageHeight($imageRow['height']);
$image->SetImageWidth($imageRow['width']);
$image->SetIsThumbnail($imageRow['isThumb']);
$this->mImages[$this->mImageCount] = $image;

where Image is a custom class and mImages is an array declared as
follows:
$this->mImages = array();

Whats happening is im executing this function
function GetImage($imageIndex)
{
return $this->mImages[$imageIndex];

}

and then trying to call a member function on the returned value
i.e.
$image = $album->GetImage(1);
$imageId = $image->GetImageId();

and im getting this error" Fatal error: Call to a member function on a
non-object in
/home/flyerweb/public_html/ImageManipulator/POCPages/DisplayAllImagesInAlbum.php
on line 30"

Object References Stored In Array Gives Me What?
Does it not create objects, store them in an array, and check that array to see if a requested class has already been instantiated, in which case it gets a reference out of the array and returns that, again by reference?

I'm getting out of memory error, meaning my scrip is using the 8 megs that PHP scripts are, by default, allowed. So I'm left to think I've done something wrong with the references.....

Interpolation Doesn't Work For A Variable In An Array In An Object
within an object function, this code:

$test2[]='test'
echo "$test[0]";

$this->test2[]='test2'
echo "$this->test2[0]
";

produces this result:
test2
Array[0]

Why do I get Array[0] instead of the value in Array[0] ?
This only seems to happen when the variable is part of an array in an
object. If, for example, I want to wrap an object's variable in single
quotes this doesn't work:

"'$this->test2[0]'"

I can put double quotes areound the single quotes:

"'".$this->test2[0]."'"

but in a long string this becomes very tedious:

"$this->name=['".$this->mbox[0]."','".$this->mbox[1]."',".$this->mbox[2]."];";

is there any way to get "'$this->test2[0]'" to work ?

Changing Object Data In An Array Of Objects
In this sample script I create an array of objects. Print out their data
with print_r().Update their data with a sub called v_set(). Print out data
showing the chnages using print_r(). I push the altered objects into a new
array and print them out again, still see the updated data. Then I iterate
over the original array again with print_r and the objects lose the updates
and have their original data.

<?
for ($i = 0; $i < 1; $i++) {
$listingObj = new Listing;
$listings[] = $listingObj;
}

foreach ($listings as $aListing) {
echo "<h3>THIS IS IN SCRIPT IN ORIG ARRAY BEFORE VARS SET</h3>";
f_array($aListing);
}

foreach ($listings as $aListing) {
$aListing->v_set(
array(
'name' => 'Jane',
'address' => Ïã Ohce Ln.'
)
);
// HERE IS BUG: WHY DO I NEED TO PUT IN NEW ARRAY?
echo "<h3>THIS IS IN SCRIPT IN ORIG ARRAY AFTER VARS SET</h3>";
f_array($aListing);
$newArray[] = $aListing;
}

foreach ($newArray as $aListing) {
echo "<h3>THIS IS IN NEW ARRAY</h3>";
f_array($aListing);
}

foreach ($listings as $aListing) {
echo "<h3>THIS IS IN ORIG ARRAY, APPARENTLY NOT
ALTERED/UPDATED?</h3>";
f_array($aListing);
}

class Listing {
var $changedVals = array();
var $name = 'Dick'
var $address = ì« Echo Ln.'

function v_set($data){
foreach ($data as $key => $value) {
$this->$key = $value;
$this->changedVals[] = $key;
}
}
}

function f_array($array) {
echo '<pre>'
print_r($array);
echo '</pre>'
}

?>

Visibility Matter On Converting Object To Array
i was into array part on tutorial and it says

i'll get an array having keys that from member variable's name

by converting an object to array.

i guessed "i can get public members but not protected, private, static
members"
(just like i got error if i try to access protected, private members
outside of object)

then i wrote a simple code to see how's it going.

################## code #######################
<?php
// for testing, each member of public, protected, private, static
CLASS test {
public $a = 'a'
protected $b = 'b'
private $c = 'c'
static $d = 'd'
}

//converting an object to array
$a = (array)new test();

var_dump($a);
echo '<br>'
/*let's see how it works (it threw not static member cuz it's not in
the object as i guessed. but it prints all other members including
public, protected, private eventhough i called this func outside of
object)*/

//i wanted to try to access by another way and it works too.
foreach($a as $i => $j)
echo "$a : '$i' => '$j'<br>
";

//i tryed to access by the key i saw on result. but it doesn't work at
all.
echo $a[' test c'] . "<br>
";
?>

################## output #######################
array(3) {
["a"]=>
string(1) "a"
[" * b"]=>
string(1) "b"
[" test c"]=>
string(1) "c"
}
<br>$a : 'a' => 'a'<br>
$a : ' * b' => 'b'<br>
$a : ' test c' => 'c'<br>
<br>

#################################################

if i try to access protected, private members directly outside of the
object, i'll get an error.

but by convering the object to array, i can get all member variables.

is it right way? then what about the visibility. i think i can be a
problem.

Is it right way to access object members?(by converting to
array)<<----------------------------- Q1.

anyway i tried to access by typing the key i saw on output ' * b' , '
test c', it didn't work.

while with the key variables i got from 'foreach', it worked.

i think i made a mistake on making the keys.

Print Array In List/menu Form Object
how i print a full column array into a list/menu form object, so that the text links to their respective page.....it is basically for a list of interviews so you click on the band name and then goto the interview page.

Fatal Error: Cannot Use Object Of Type PEAR_Error As Array
im USING PEAR serialize class. when ever i pass an integer value in array this error massages comes out :: Fatal error: Cannot use object of type PEAR_Error as array

i need the integer value for mathematical operations. ive already used typecast, intval, to_number.. etc... it didnt work.

Global Object From Object?
I'm trying to set a object as global for access through out the rest
of my script ... {a basic SQL accessing object} however if I try
calling the object from with in another object it acts as if it isn't
global and hasn't been accessed at all ... weather I decalre it from
inside the object or declare it outside the object
I would rather not have to resort to the standard of refrenceing sence
I plan on having modular support and having this one object be a
global rathen then everyone refrencing it would just be easyer for
people to understandanyways heres some of the code
and mind you this is pretty basic so far

---------index.php----------------
<?php
include_once("config.php");
include_once("libs/mod.class.php");
include_once("libs/DataBase.class.php");
include_once("libs/main.class.php");
$site= new main();
$site->init();
$site->loop();
$site->close();
?>
--------end------------------------
--------main.class.php-----------
<?php
global $db;
class main {

function init () {
global $db;
$db = new DBAccess($config['database']);
}
function loop () {}
function close () {
$db->DBKill();
}
}
?>
----end-------------------------

---error------------------------
Fatal error: Call to a member function on a non-object in
main.class.php on line 11
-------------end----------------

Php Object To Javascript Object?
Is there a way to convert a Php object to a JavaScript Object onn client side ?

I tried using JSON
$output = json_encode($Obj);
echo $output."";

But I got a slight error,
Warning: [json] (json_encode_r) type is unsupported, encoded as null. in
whats the best way I should do this ?

Illegal Offset Type For Array. Object To Integer Convertion
The code is as ...

$folderlistfile = $path."xmlfile.xml";

/*

<list>
<details id="2">
<name>Books</name>
<mainid>0</mainid>
</details>
<details id="1003">
<name>CDs</name>
<mainid>0</mainid>
</details>
</list>

*/

$list = simplexml_load_file($folderlistfile);

foreach($list as $sno=>$details) {
if($details->isdeletable) {
if($details->mainid) {

echo "<br /mainid = ".$details->mainid." : id =
".$details['id']." ";
var_dump($details->mainid);
$mainid = $details->mainid;
settype($mainid, "integer");
var_dump($mainid);

// I want to save the details in an array
//$listarr[$mainid][] = $details['id']; //Warning: Illegal offset
type
//$listarr[$details->mainid][] = $details['id']; //Warning: Illegal
offset type
}
}
}

echo, var_dump will output as follow ...

mainid = 0 : id = 2
object(SimpleXMLElement)#5 (1) { [0]= string(1) "0" }
UNKNOWN:0

mainid = 0 : id = 1003
object(SimpleXMLElement)#4 (1) { [0]= string(1) "0" }
UNKNOWN:0

Both of this generate the error : Warning: Illegal offset type

$listarr[$mainid][] = $details['id']; //Warning: Illegal offset type
$listarr[$details->mainid][] = $details['id']; //Warning: Illegal
offset type

and page doesn't execute furthur of this line.

I suppose it is because the array key is an object. How do I convert it
to integer.

print_r($details->mainid) displays SimpleXMLElement Object ( [0] =0
)
print_r($mainid) : nothing is displyed. even mainid = 0 : id = 2 is
not displayed.


System: free bsd, php 5

As is mentioned in the code, I want to craete an array as

either
$listarr[$mainid][] = $details['id']; //Warning: Illegal
offset type
or
$listarr[$details->mainid][] = $details['id']; //Warning:
Illegal offset type

Get Object Value
I have the following class shop and function. makelist
makelist() function is going to generate the dummy data for testing.

At the end when displaying the id and shopname I only get the shopname for
both $shoplist[$i]->getID() and $shoplist[$i]->getName() why is that?

Class Shop{
var mID;
var mName;

function setID( $id ){
$this->$mID=$id;
}
function getID(){
return $this->$mID;
}
function setName( $name ){
$this->$mName=$name;
}
function getName(){
return $this->$mName;
}
}

function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}


$shoplist = makelist();

for( $j=0;$j<10;$j++){
echo "ID: " . $shoplist[$i]->getID()."Name: ".$shoplist[$i]->getName();
}
}

The COM Object
I've heard a few people singing the praises of ASP as it supports / interfaces with the COM Object. I also note that PHP4 has some support for the COM Object. Unfortunately I have no idea what it is! Can somebody explain what it is, and why I need to learn about it, if at all?

One Object
I want to build one object that will be reuse all the time, so I just
need to create it once for all, how can I do that. A sort of static object.

PHP Object Bug?
I am experiencing a strange problem when building an object tree: PHP Code:

Com Object With PHP How To Use?
I have a COM Server that create an object with PHP, then from the html
input sentence using onchange, goes to a javascript function, as
parameter the input value, within this value i want to get from the COM
Server an answer. From PHP the object is created with new, as:
$coi = new COM("Coi4ImplP.Coi4");
and I can get from the server the answer as:
$hresult=$coi->Empresa($_POST["empresa"]);
$ruta=$coi->Ruta();
$niveles=$coi->Niveles();
$nombree=$coi->Nombre();
but in the input area from the html page in the from like:
<td><input type="text" size="25" name="cuenta[<? echo($n); ?>]"
value="<? echo($cuenta[$n]); ?>" onChange="<? echo
rdes($cuenta[$n]);?>"></td>

the function is:
function rdes(cta){
var <?php global $coi; $k=$coi->Ruta(); echo('$k='.$k); ?>;
alert($k);
}

I get an error in the page, if I change $k=$coi->Ruta(); to $k=5; it
works fine.

Can Object Contain Object That Contains It?
If I have a class called $controllerForAll
which has an arrray of all the objects that exist, what happens if one
of those objects, when it is created, takes a reference to the object
that contains it? Do bad things happen?

class McShow {

var $dsArray;
var $htmlObject;
var $loopObject;
var $getInfoObject;
var $controllerForAll;

function McShow() {
$this->controllerForAll = $GLOBALS["controllerForAll"];
}

Object Id
I am reading a PHP5 book for fun. The book gives the attached code, which
supposed to print object id, but throw exception in 5.2.5. I assume that
this can be resolved by defining __toString() method. My question is when
this stopped working (which version)? ....

Object Question
Can anyone help us out

I have returned an object from a class
and done a var_dump on the object

object(b)(1) { ["c"]=> string(14) "Helloworld" }

How can i access the data, ive tried echo but all i get is

Object


Object Orientation
Does anybody know of a good tutorial on Object Oriented (classes) programming for PHP? My book was very vague with the examples.

PHP OO - Object Oriented
<< programming design on PHP - Oject Oriented >>
which one you use for member infos?
_______________________________
For the fields of one object's data , you like to use...

$member->id
OR
$member->info['id']
_______________________________

For Listing, you feel which one is better?
Looping $n ......

$member[$n]->id
OR
$member_list[$n]['id']
_______________________________


XMLDOM As A COM Object
I work on a windows server that has IIS and Apache running, in this case I am working with the IIS server.

I have an xml file that I want to apply an xsl file too, based on user selection. I originally setup a small javascript that let me do it, works perfect except for its only usable by PC IE users, noone else. Since the javascript version uses a com object I figured I would just uses the same com object through PHP and thus make the transformation server side, rather than client side.

Exact same XML and XSL file, I even created a new extremely basic xml and xsl file just in case it was some of the fancy stuff causing the problem, works perfect with javascript, errors in PHP with:

Warning: Invoke() failed: Exception occurred. Source: msxml3.dll Description: The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document. in D:Websitestylesheetsxslt.php on line 15

Line 15 being the transformNode line. Anyone know why this wouldnt work in PHP? I dont have Sablotron setup and was hoping I wouldnt have to go that route. Code:

PHP Communicating To A COM Object
Have a client requirement for a cms system, which I am proposing to be
done with a PHP open source system (phpwcms). The client already has a
client login authentication script running off of a customized
windows-based COM object. Is it possible for PHP to communicate with
this object (which will return session variables)... making them
available to other PHP-based scripts relying on sessions.

Object Oriented PHP
I have written three classes : validate.class.php,
report_handler.class.php, sentry.class.php.

The problem is that the "validate" class uses the "reporting" class and
the "sentry" uses the "validate" that uses the "reporting".

So I end up having something like that inside sentry.class.php:
$validate->report->getReport();

But although that's working... it doesn't seem to be really OO :p

So can you tell me what I can do ?

If what I am saying doesn't make any sense at all... let me know and I
will try to explain it better.

Bellow I have some snippets from each class that may help you to
understand what I am trying to do.
************************************************** ******************
class report_handler {
....
/*This Function populates the array with reports (ERRORS,MESSAGES)
*Syntax: setReport($reportType,$string)
*/
function setReport($reportType,$string=''){
if($this->validateReportTypes($reportType)) {
$this->counter++;
$this->report[$this->counter] = array( 'category' => $reportType,
'description' => $string);
}
else
echo "Report type '".$reportType."' is not valid";
}
/* Output the report to the user
*/
function getReport() {
if(is_array($this->report))
{
foreach($this->report as $i => $value)
{
echo "<pre>".
$value['category'].': '.
$value['description']
."</pre>";
}
}
}
....
}
/*****************END of class report_handler********************/

class validate {

function validate()
{
$this->report = new report_handler();
}

function checkEmail($email)
{
// checks proper syntax
if(
!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/',
$email))
{
$this->report->setReport('Error','Syntax Error');
return false;
}
....
}
}
/*****************END of class validate ********************/
class sentry {
var $user_id;
var $session_timeout;
function sentry()
{
$this->report = new report_handler;
}
....
function validateLoginForm()
{
$validate = new validate();
if($validate->checkEmail($_POST['email']))
{
$this->loginUserName = $_POST['email'];
$this->loginPassword = $_POST['passwd'];
return true;
}
else
{
$validate->report->getReport();
return false;
}
}
.....
}
/*****************END of class sentry********************/

Getting Info Into A Object..
I'm sitting and trying to understand this OOP - and need to create a
class wich can do the following..

ShowBlocks() - Displays the data wich is inside it - If empty creates a form
wich sends the info back to the Object, wich show the stuff..
AddBlock( $type ) - Creates an empty blok - wich is addet to a blocks area
object...( Or somethin like it )
Store() - safes the info into a file, and updates mySQL...

I have figured out most of the stuff but the way to get the empty block ->
creating form with some different strings/textbloks and a file -> putting
stuff into object -> now showing what its looks like and aking if i want to
add a extra block....... now showing x blocks then asking if i want an extra
block - i haven´t got a clue of how to do it !

Does anyone of you have an example with an object thats goes : See im a
empty object -> here you can put an line into me -> see im not empty now (
showing the string) do you want to add an extra line ? - ect ect..

Delete An Object ?
I use OOP with PHP4 and i don't understand something.

I have 2 classes VISIT & PLANNING like that:

class clVISIT {
var $when;
var $where;

//constructor
function clVISIT($_when,$_where) {
$this->when = $_when;
$this->where = $_where;
}
}

class clPLANNING {
var $who;
var $visit = array();

//constructor
function ClPLANNING($_who) {
$this->who = $_who;
for ($i=0;$i<10;$i++) { $visit = new clVISIT("foo".$i , "foobar".$i ) ; }
}

}

Ok, in the last constructor, we can see that i create new clVISIT
object. My question is: how can i delete some of them in the same
constructor ? is there a word like "new" but to delete ?

Object Not In Context
I am just experimenting with functions and object oriented PHP for the first time, and am getting this error:

Fatal error: Using $this when not in object context in /var/www/vhosts/domain.com/httpdocs/script.php on line 127 Code:

OOP PHP - Passing An Object
I have a class to control the database connection, and then i've been trying to call it from other methods. It is not letting me do so, for some odd reason. I tried using extends, but by script will not connect. Here is a sample. PHP Code:

Object Oriented PHP... Why?
I just have a question. First off, PHP is the only language that I've ever used, so I don't understand too many concepts of coding. I've looked at OO PHP examples versus 'static' (what would you call it?). I can't seem to find any advantages. Can anyone point me to some examples an maybe explain what OO PHP offers over 'regular'?

Object Without Class
I have a question regarding next few lines of code.

<?php
$person->name = "John Doe";
$person->age = "26";
?>

What does this piece of code actually do? It seems to create object $person,
but i am not shure if i can create objects without defining class first? I'm
little confused here :) This reminds me of structures in C...

Object Syntax
I keep seeing this syntax come up when working with classes, but I have yet to notice an explanation of the following type of syntax: PHP Code:

Object Suicude
Is there a way for an object to unset itself in PHP4?

Of course I could unset it from outside, but I would like to keep the code
clean. The object has a method which deletes it's "footprint" in the
database, and as the idea is that we don't need the object once itsin't in
the DB it would be nice if the same method could get rid of the PHP object
iself as well.

How To Get Object In Pages !
actually I am using php-java bridge to call some
functions of java from my php page. The value returned are encapsulated
in some object and data in that object are fetched from database. What
I want to do is that when I post my page to same page or other page I
again need that data (or object). I don't want to hit the database
again for same values. So how and where to set the object values. I
think I can set it in request object like in java we do
(request.setAttribute(String, Object)). I am focibly setting the values
like $_REQUEST['list']=somelistObject. But I am not getting the data
after submission of page. same operation with $_SESSION also is not
working. If somebody knows how to do this,

Object Oreinted
It may be a bad question, but..
What is the difference between Object Oriented Language and Object
Orinted Srcipting? The code is simplier in scripting than the code in
other programming language? or..

Searching A Value In An Object?
i use in_array or array_search to look for array values, is there something that does the same thing for object variable values?


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