jjacquay712 Posted July 21, 2009 Share Posted July 21, 2009 I was looking at some JavaScript and was wondering if there was an equivalent in PHP. Basically you can create and access object properties dynamically by using something called Square Bracket Syntax. It looks like this: document.body Or you could do this: document['body'] By using Square Bracket Syntax, you could create object properties dynamically using a loop like this: for (var n = 0; n < 10; n++) { document[n] = "whatever"; } Is there anyway to do this in PHP, without using an associative array? Thanks, John. Link to comment https://forums.phpfreaks.com/topic/166854-solved-create-object-properties-dynamicly/ Share on other sites More sharing options...
ldougherty Posted July 21, 2009 Share Posted July 21, 2009 Use PHP to do what exactly? If you are trying to change document configuration why not just use the javascript in your PHP? Link to comment https://forums.phpfreaks.com/topic/166854-solved-create-object-properties-dynamicly/#findComment-879791 Share on other sites More sharing options...
jjacquay712 Posted July 21, 2009 Author Share Posted July 21, 2009 That was just an example. I want to be able to create an object property dynamically using PHP like in the JavaScript example above. Link to comment https://forums.phpfreaks.com/topic/166854-solved-create-object-properties-dynamicly/#findComment-879801 Share on other sites More sharing options...
jjacquay712 Posted July 21, 2009 Author Share Posted July 21, 2009 I found a solution with a Google search. http://stackoverflow.com/questions/829823/can-you-create-class-properties-dynamically-in-php Link to comment https://forums.phpfreaks.com/topic/166854-solved-create-object-properties-dynamicly/#findComment-879803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.