VB programmer switching to PHP... few questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kaervek
Forum Commoner
Posts: 25
Joined: Fri Jul 08, 2005 7:17 am
Location: Newfoundland
Contact:

VB programmer switching to PHP... few questions

Post by Kaervek »

I have been picking up a bit of php lately and i really like it
i have one quick question for all u guru's that would really save me some time
and if i have more questions in the future i'll reuse this thread instead of spamming u guys
thanks in advance.

Q. Does php have an equivalent to VB's "with" statement?

______________________________
Sept 5: Question Asked in a new reply, scroll down
Last edited by Kaervek on Tue Sep 05, 2006 7:30 am, edited 1 time in total.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Not exactly..

vb:

Code: Select all

With Object
    .prop1 = 1
    .prop2 = 2
End With
php:

Code: Select all

$object->prop1 = 1;
$object->prop2 = 2;
but if you are only using the values and not assigning new ones, you can:

Code: Select all

foreach ($object as $prop) {
    echo $prop;
}
or similar.
Kaervek
Forum Commoner
Posts: 25
Joined: Fri Jul 08, 2005 7:17 am
Location: Newfoundland
Contact:

Post by Kaervek »

well in many cases i will need to assign to the properties and foreach really doesnt do the same
so i guess the answer is no, i have to reference the object at each call.

hmm i suppose if i had an object that contained another object etc i could go

Code: Select all

myWithObject = Object1->Object2->Object3;
myWithObject->myFunction();
myWithObject->Property1 = x;
etc...
how do you destroy an object?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

use function unset();

objects are also destroyed automatically when the PHP engines' reference counter for said objects reaches zero. Although for all intents and purposes, once you lose all your references, you won't have access to the object anyway..

Code: Select all

<?php

$object = new stdClass;

$object2 = $object; //objects are always passed by reference when assigning.
$object = null; // this reference to the stdClass object is no longer valid. But the object still exists in $object2.

$object3 = $object2;

unset($object2); // object is destroyed. Any references to object will not be valid anymore, ergo $object3 == null.

?>
EDIT: after a quick test, the above is only correct if you pass the object as a param in functions/methods. however the literal above is incorrect and the object will still exist, unless you assign by ref (=&)
Kaervek
Forum Commoner
Posts: 25
Joined: Fri Jul 08, 2005 7:17 am
Location: Newfoundland
Contact:

Post by Kaervek »

Q. if i have written a user control in visual basic and compiled it into an OCX file, can i use php to embed that control into a form on a website? and if so how would i go about it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Kaervek wrote:Q. if i have written a user control in visual basic and compiled it into an OCX file, can i use php to embed that control into a form on a website?
Yes, it's possible.
Kaervek wrote:if so how would i go about it?
Exactly as if you were writing a static HTML page. You may need/use echo(), but it's not required if you are outside of PHP already.
Post Reply