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. Quote 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? Quote 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. Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.