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
VB programmer switching to PHP... few questions
Moderator: General Moderators
VB programmer switching to PHP... few questions
Last edited by Kaervek on Tue Sep 05, 2006 7:30 am, edited 1 time in total.
Not exactly..
vb:
php:
but if you are only using the values and not assigning new ones, you can:
or similar.
vb:
Code: Select all
With Object
.prop1 = 1
.prop2 = 2
End WithCode: Select all
$object->prop1 = 1;
$object->prop2 = 2;Code: Select all
foreach ($object as $prop) {
echo $prop;
}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
how do you destroy an object?
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...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..
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 (=&)
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.
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Yes, it's possible.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?
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.Kaervek wrote:if so how would i go about it?